This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Arduino-PC Serial Communication (arduino code)

By: a guest on Jan 21st, 2011  |  syntax: Bash  |  size: 0.54 KB  |  views: 1,080  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data