Advertisement
Midge

Serial to Arduino Pins Test

Apr 12th, 2011
475
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. /* Controlling pins on an Arduino port via Serial */
  2.  
  3. byte incomingByte = 0; // variable for incoming serial data
  4.  
  5. void setup() {
  6. Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  7. DDRB= B00111111; //Set Port B as output (Pins 8 to 13)
  8. /* it's an 8 Bit port but two highest pins
  9.    are used by crystal and not accessible */
  10. }
  11.  
  12. void loop() {
  13.  
  14. // Listen for incoming Serial data:
  15. if (Serial.available() > 0) {
  16. // read the incoming byte:
  17. incomingByte = Serial.read(); //Read from Serial Port
  18. PORTB=incomingByte; //output data to Port B
  19.  
  20. /* so, if you send 8 to serial,Port B will become 00010000
  21. send 3 Port B will become 00000011
  22. send 2 Port B will become 00000010
  23. send 6 Port B will become 00000110
  24. send 255 Port B will become (11)111111
  25. and so on
  26.  
  27. NB this is assuming P.D sends data as actual numbers (Bytes) and not ASCII data.
  28. if it doesn't there is a workaround.
  29. Midge
  30. */
  31.  
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement