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.
There's nothing obviously wrong with what you've got. Have you done a println on the sensorValue after you call analogRead? If the values aren't in the range 0-255 that would cause problems (which are easily solved).