Advertisement
Guest User

Arduino-PC Serial Communication (arduino code)

a guest
Jan 21st, 2011
1,523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.54 KB | None | 0 0
  1. #define photo 0
  2. #define LED 5
  3.  
  4. int val = 0;
  5. int ledState = 0;
  6. int counter = 0;
  7.  
  8. void setup(){
  9.   Serial.begin(9600);
  10.   pinMode(LED, OUTPUT);
  11. }
  12.  
  13. void loop(){
  14.   counter++;
  15.   if(counter >= 10000){
  16.     updatePhoto();
  17.     counter=0;
  18.   }  
  19.  
  20.   if(Serial.available() >0){
  21.     //read the incoming byte
  22.     ledState = Serial.read();
  23.   }
  24.  
  25.   if(ledState == 1){
  26.     digitalWrite(LED, HIGH);
  27.   }else{
  28.     digitalWrite(LED, LOW);
  29.   }  
  30.    
  31.   //delay(100);
  32. }
  33.  
  34. void updatePhoto(){
  35.   val = analogRead(photo);
  36.   Serial.println(val);
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement