Processing code error
in
Integration and Hardware
•
1 year ago
Hi,
I wrote the following code in order to send the serial byte of a letter to my arduino, but I am getting an error in the serial.write portion of the code. Any ideas? Also if you have a better way to write it out, please le the know. I am not an expert coder and I got part of the code from the following website:
Processing Code:
- import processing.serial.*; //Import the serial library into your sketch
- import cc.arduino.*; //Import the Arduino-Firmata library into your sketch
- Arduino arduino; //Create an instance of Arduino named arduino (can be any name)
- int ledPin;
- char serial;
- void setup() {
- size(200, 200);
- print(arduino.list());
- arduino = new Arduino(this, Arduino.list()[0], 9600); //defines arduino our board and sets the communication rate
- arduino.pinMode(ledPin, Arduino.OUTPUT);
- }
- void keyPressed() {
- print(key);
- delay(10);
- switch (key) {
- case 'e':
- case 'E':
- serial.write( 'e' );
- break;
- case 'i':
- case 'I':
- serial.write( 'i' );
- break;
- case 'q':
- case 'Q':
- serial.write( 'q' );
- break;
- }
- };
- void keyReleased() {
- delay(10);
- switch (key) {
- case 'e':
- case 'E':
- serial.write( 'z' );
- break;
- case 'i':
- case 'I':
- serial.write( 'p');
- break;
- case 'q':
- case 'Q':
- serial.write( 'l');
- break;
- }
- };
Arduino Code:
- int ledPin;
- int ledPin13 = 13;
- int ledPin12 = 12;
- int ledPin11 = 11;
- int sensorPin = A0;
- int sensorValue = 0;
- int analogPin = 0;
- char c = 0;
- void setup()
- {
- pinMode( ledPin, OUTPUT );
- Serial.begin( 9600 );
- }
- void loop()
- {
- // Wait for a character to arrive at the serial port.
- if( Serial.available() > 0 )
- {
- // Read one byte (character).
- c = Serial.read();
- switch( c )
- {
- case 'e':
- Serial.println("case e received");
- digitalWrite( ledPin13, HIGH );
- Serial.println("Pin 13 HIGH");
- break;
- case 'i':
- Serial.println("case i received");
- digitalWrite( ledPin12, HIGH );
- Serial.println("Pin 12 HIGH");
- break;
- case 'q':
- Serial.println("case q received");
- sensorValue = analogRead( sensorPin )/4;
- analogWrite(ledPin11, sensorValue);
- Serial.println("Pin 11 HIGH");
- break;
- case 'z':
- Serial.println("case q received");
- digitalWrite( ledPin13, LOW );
- Serial.println("Pin 13 LOW");
- break;
- case 'p':
- Serial.println("case p received");
- digitalWrite( ledPin12, LOW );
- Serial.println("Pin 12 LOW");
- break;
- case 'l':
- Serial.println("case l received");
- digitalWrite( ledPin11, LOW );
- Serial.println("Pin 11 LOW");
- break;
- }
- }
- }
1