Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int potPin = A0; //Analog pin 0
- int lastRead = 0;
- void setup(){
- Serial.begin(9600);
- }
- void loop(){
- sendReading(); //send the analog reading out
- }
- void sendReading(){
- //read the digital pin, send a value only if it has changed
- int potValue = analogRead(potPin) / 4; //divide by 4 so the value is 0-255
- //We ONLY want to send changes so the serial buffer does not overflow with unneeded values
- if(potValue != lastRead){
- send(potValue);
- lastRead = potValue;
- }
- }
- void send(int value){
- value = constrain(value, 0, 255); //cant send anything higher than 255
- Serial.write(value); //send that value through the serial port
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement