Advertisement
Guest User

potFader Send

a guest
Sep 24th, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. int potPin = A0; //Analog pin 0
  2. int lastRead = 0;
  3.  
  4. void setup(){
  5.   Serial.begin(9600);
  6. }
  7.  
  8.  
  9. void loop(){
  10.   sendReading(); //send the analog reading out
  11. }
  12.  
  13.  
  14. void sendReading(){
  15.   //read the digital pin, send a value only if it has changed
  16.   int potValue = analogRead(potPin) / 4; //divide by 4 so the value is 0-255
  17.  
  18.   //We ONLY want to send changes so the serial buffer does not overflow with unneeded values
  19.   if(potValue != lastRead){
  20.     send(potValue);
  21.     lastRead = potValue;
  22.   }
  23.  
  24. }
  25.  
  26.  
  27. void send(int value){
  28.   value = constrain(value, 0, 255); //cant send anything higher than 255
  29.   Serial.write(value); //send that value through the serial port
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement