Hi there !
a made a code on arduino that takes two infos :
-
a serial signal from a Python code
-
and a push button
the idea is to trigger the same thing either its from a PC or a push button (or multiple ones)
technically, both are working. However when i launch my python program,
let's say the LED is ON, it sets immediately OFF. but i need only one program (not two files , each one for ON and OFF commands)
the idea behind this is to have a desktop icon that makes the same job as the push button. to switch ON or OFF a lamp from both commands for example.
here's the python code :
import serial
import time
node = serial.Serial(port='COM3',baudrate=9600, timeout=.1)
time.sleep(2)
node.write(b'H')
print(node.readline())
and the Arduino code :
#define led 10
int x;
bool toggle;
int _button = 8;
void setup()
{
pinMode(led, OUTPUT);
pinMode(_button, INPUT);
Serial.begin(9600);
Serial.setTimeout(1);
}
void loop()
{
byte probe = digitalRead(_button);
if(probe == LOW)
{
toggle = !toggle;
Serial.println("The button line have been activated");
}
if(Serial.available() > 0){
x=Serial.read();
Serial.print("Python, did you say.. ");Serial.print(x);Serial.print(" ? ");
if(x == 'H')
{
toggle = !toggle;
}
}
if(toggle == HIGH)
{
digitalWrite(led, HIGH);
}
else if(toggle == LOW)
{
digitalWrite(led, LOW);
}
delay(250);
}
i wonder what could create that reset command