Advertisement
subnet

Arduino sending & receiving data to & from Beaglebone Black

Aug 18th, 2014
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. /*
  2.  * using PHPSerial (https://github.com/Xowap/PHP-Serial) on Beaglbone Black to send ON/OFF to Arduino's LED
  3.  * and read LM35 sensor temperature. See Arduino code here: http://pastebin.com/J6fCNguP
  4.  * almost all code is by: http://paolosarteschi.altervista.org/wp/?p=375
  5.  * to connect Arduino & Beaglebone Black use:
  6.  * www.instructables.com/id/How-to-make-a-BeagleBone-and-an-Arduino-communicat/?ALLSTEPS
  7.  *
  8. */
  9.  
  10. int tempPin = 0;// pin cui è collegato il sensore
  11. int temp;
  12.  
  13. int LED = 13;
  14. int statoled;
  15. char oldval='a',val = '0';
  16. void setup() {
  17.   pinMode(LED,OUTPUT);
  18.   Serial.begin(9600);
  19. }
  20.  
  21. void loop () {
  22.  
  23.   val = Serial.read();
  24.   if(val!=oldval)
  25.   oldval=val;
  26.  
  27.   if(oldval=='s'){
  28.   digitalWrite(LED,LOW);
  29.   Serial.print(0);
  30.   }
  31.   else if (oldval=='a'){
  32.   digitalWrite(LED,HIGH);
  33.   Serial.print(1);
  34.   }
  35.   else if (oldval=='r'){
  36.   statoled = digitalRead(LED);
  37.     if (statoled==0){
  38.     Serial.print(0);   
  39.     }
  40.     else {
  41.     Serial.print(1);   
  42.     }
  43.   }
  44.  
  45. temp  = ( 4.4 * analogRead(tempPin) * 100.0) / 1024.0;
  46. Serial.print(temp);
  47. delay(200);
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement