Advertisement
igendel

Python COM PORT tester Arduino tester

Nov 10th, 2020
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Test program for the Python code at https://pastebin.com/dxCjCSn7
  2. // by Ido Gendel, 2020
  3.  
  4. // Upload this to an Arduino Uno, close the IDE,
  5. // and connect to the arduino's COM PORT using the Python program.
  6. // If everything works it will blink slowly,
  7. // otherwise it will blink fast.
  8.  
  9. void setup() {
  10.   pinMode(13, OUTPUT);
  11.   Serial.begin(115200);
  12. }
  13.  
  14. uint8_t LEDState = 0;
  15.  
  16. void loop() {
  17.  
  18.   uint8_t x;
  19.   int16_t y;
  20.  
  21.   x = random(256);
  22.   Serial.write(x);
  23.   digitalWrite(13, LEDState);
  24.   delay(100);
  25.   y = Serial.read();
  26.   x += 1;
  27.   delay((y != -1) && (uint8_t(y) == x) ? 900 : 0);
  28.   LEDState = 1 - LEDState;
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement