This is the code I worked on over summer and it worked perfectly fine. Now I after a few months, it magically doesn't want to work anymore. The following is my ARDUINO code:
int ledPin;
int ledPin13 = 13;
int ledPin12 = 12;
int ledPin11 = 11;
int sensorPin = A2;
int sensorValue = 0;
int analogPin = 0;
char c = 0;
void setup()
{
pinMode( ledPin13, OUTPUT );
pinMode( ledPin12, OUTPUT);
pinMode( ledPin11, OUTPUT);
Serial.begin( 57600 );
}
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 )/32;
Serial.print(sensorValue);
analogWrite(ledPin11, sensorValue);
Serial.println("Pin 11 HIGH");
break;
case 'z':
Serial.println("case z 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;
}
}
}
Next is my 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)
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:
So I have been using processing for a while and I managed to come up with a code that allows you to set any pin on high when you press a certain "key" that its assigned to. The problem is I cannot get any code that uses the analog pins (variable values) to work with processing and arduino.
First- I am running firmata on arduino which allows me to communicate with processing. I have a mega.
Second- I have the following code used in processing:
void keyPressed() {
switch(key) {
case 'e':
***********
}
};
This little portion of the code simply states when key 'e' is pressed, execute ***** code. I usually use arduino.digitalWrite(pin, Arduino.HIGH) as my code [this is what I want to change]
simple enough right.
Now I have a dimmer switched hooked up to the arduino using Analog 1 pin. Now what I want to happen is when I press 'e', I want it to read the value coming from my dimmer and then execute that value read to pin 12.
I have tested the hook up of the dimmer with the arduino sample code given for dimming a LED (just changing the pin values it was assigned too to fit my values) and it worked just fine. So I know my hookup is correct and should work.
Now for my code (or my **** in the above part) is the following:
int pinout= 12;
int sensorValue;
potPin= 1;
case 'e':
sensorValue= arduino.analogRead(potPin);
arduino.analogWrite(pinout, sensorValue);
when I run the code, I get nothing. If you see an error in my code or know a different way to doing this (maybe modifyineeg firmata) please let me know! Even if I need to type in the values to assign to it ( 0 - 255) instead of using my dimmer, I am fine with that. I just want to be able to adjust my values. thanks!
I also tried:
arduino.digitalWrite(pinout, sensorValue);
No luck.
Also I have been having wireless communication problems in which the code I send out doesn't always get received (I am using xbee). I am unsure if its the code I am sending out is too much, or the arduino isn't receiving it due to the code programmed on there, or if its the xbees. Yes, quite a handful of stuff I asked, sorry for the long message! any help would be appreciated.