Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Send a byte through Serial to be used by Processing
- * I am pretty sure the original code was written by Tom Igoe
- */
- int analogPin = 0;
- int analogValue = 0;
- int forwardLedPin = 3;
- int backwardLedPin = 11;
- int pwmValue = 0;
- void setup()
- {
- // start serial port at 9600 bps:
- Serial.begin(9600);
- }
- void loop()
- {
- // read analog input, divide by 4 to make the range 0-255:
- analogValue = analogRead(analogPin);
- analogValue = analogValue / 4;
- Serial.print(analogValue, BYTE);
- // figure out which LED should be on
- // if the values are between 0-127, then the backwardLed should be lit
- if(analogValue <= 127){
- pwmValue = map(analogValue, 127, 0, 0, 255);
- analogWrite(backwardLedPin, pwmValue);
- analogWrite(forwardLedPin, 0);// this will make sure the other LED is off
- }
- // if the values are between 128-255, then the forwardLed should be lit
- // pwm an led to show that the pot is working
- if(analogValue >= 128){
- pwmValue = map(analogValue, 128, 255, 0, 255);
- analogWrite(forwardLedPin, pwmValue);
- analogWrite(backwardLedPin, 0);// this will make sure the other LED is off
- }
- // pause for 10 milliseconds:
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement