Can anyone help me with this issue.
We created an arduino project. We listen microswitch. If switch click, Arduino send basic serial data. And C# application read serial port.
This solution is working but after more times (3Hours, 5Hours,..) system stoped. Error message is "a device attached to the system is not functioning" Solution: Usb remove and retry plug system is going to running.
We are try putty.exe maybe problem C# project but don't working.
If microswitch click don't flash "TX" or "RX" led.
const int button = 3;
uint64_t bounceTime = 50;
uint64_t holdTime = 250;
uint64_t doubleTime = 500;
uint64_t lastReading = LOW;
uint64_t hold = 0;
uint64_t single = 0;
uint64_t onTime = 0;
uint64_t lastSwitchTime = 0;
void setup() {
pinMode(button, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
int reading = digitalRead(button);
if (reading == HIGH && lastReading == LOW) {
onTime = millis();
}
if (reading == HIGH && lastReading == HIGH) {
if ((millis() - onTime) > holdTime) {
hold = 1;
}
}
if (reading == LOW && lastReading == HIGH) {
if (((millis() - onTime) > bounceTime) && hold != 1) {
onRelease();
}
if (hold == 1) {
delay(5000);
reading = digitalRead(button);
if(reading==LOW){
Serial.println("B");
}
hold = 0;
}
}
lastReading = reading;
if (single == 1 && (millis() - lastSwitchTime) > doubleTime) {
single = 0;
}
}
void onRelease() {
if ((millis() - lastSwitchTime) >= doubleTime) {
single = 1;
lastSwitchTime = millis();
return;
}
if ((millis() - lastSwitchTime) < doubleTime) {
single = 0;
lastSwitchTime = millis();
}
}