Advertisement
Midge

Osc_Ex Arduino Code to Read Serial Data

Apr 13th, 2011
472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.72 KB | None | 0 0
  1. /* controlling pins on a port via Serial */
  2.  
  3. byte incomingByte = 0; // variable for incoming serial data
  4.  
  5.  
  6. void setup() {
  7. Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  8. DDRB= B00111111; //Set Port B as output (Pins 8 to 13) Two MSB pins are for Xtal and unusable
  9. }
  10.  
  11. void loop() {
  12.  
  13. // Listen for incoming Serial data:
  14. if (Serial.available() > 0) {
  15. // read the incoming byte:
  16. incomingByte = Serial.read(); //Read from Serial Port
  17. PORTB=incomingByte; //output data to Port B
  18.  
  19. /* so, if you send 8 to serial,Port B will become 00010000
  20. send 3 Port B will become 00000011
  21. send 2 Port B will become 00000010
  22. send 6 Port B will become 00000110
  23. send 255 Port B will become (xx)111111
  24. and so on
  25. */
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement