Dear all, my partner Jean and I are trying to write a short code into processing that will let us send a digital high signal to an arduino board via serial connection to turn on an LED when a variable present in the processing code reaches a certain value. We currently have our arduino set up via the usb port; we have data that streams into the processing platform and is processed there. So, what we are trying to do is use that data to turn on an LED (or even dim it, as a result of data value, if possible). We have all libraries installed in processing to control arduino. We have also upload the following code to the arduino:
//used to store what we receive
int incomingData = 0;
//the pin on which you connect the anode (+) of the LED
byte ledPin = 13;
//this function runs only once (after reset)
void setup(){
//open the serial port and set data rate to 9600 bps
Serial.begin(9600);
//set the pin we use to OUTPUT so we can power-up the LED
pinMode(ledPin, OUTPUT);
//send our status
Serial.println("Program started.");
Serial.print("The LED connected to GND and PIN ");
Serial.print(ledPin, DEC);
Serial.println(" will be on if you send '1' or off if you send anything else!");
}
//this function runs continuosly (after setup)
void loop(){
//look if we have data
if (Serial.available() > 0) {
//get the sent data
incomingData = Serial.read();
Serial.print("We received : ");
Serial.write(incomingData);
Serial.print("The LED is : ");
//49 = ASCII code for '1'
if (incomingData == 49){
digitalWrite(ledPin, HIGH);
Serial.println("ON");
} else {
digitalWrite(ledPin, LOW);
Serial.println("OFF");
}
Serial.println();
}
}
We already have a processing code, which interprets EEG signals from the Neurosky Mindset and displays them (it is MindsetViewer and can be found online).
We are just trying to add something to this code to control an LED with the value of one of the signals that is acquired.
Thanks so much to anyone that can help!
1