Hello guys!
I have created a program that works on Arduino, namely mega, but when uploaded on Tiny45, it does not work.
The general idea is to follow the data above HT and measure time how long we are above HT, if certain time has passed then turn on the led (ledState, toggle). However, if we wiggled our hand twice-fast enough (see below, it should be below 500) then we turn on the second led (ledState1, toggle). Indeed there is fading in the first block of code as well, which only work if turned on the ledState1.
I am using the same sensor all along. Otherwise I am programming in Arduino IDE.
Please have a look at the code below and let me know, if you have any hints why this cannot be uploaded to tiny, what could be wrong?
Any help, suggestions, hints are very much appreciated!
Best.
//"first" hand if (Sensor.readProximity() > HT) { fadeUp = !fadeUp; // fade rottation! startTime = millis(); //elapsedTime = 0; while (Sensor.readProximity() > HT) { currentTime = millis(); elapsedTime = currentTime - startTime; //FADING (between 500 and 2000) while (elapsedTime > 500 && A) { A = true; myFading(); //Serial.print(elapsedTime); Serial.print("\t"); Serial.print("fadeUp: "); //Serial.print(fadeUp); Serial.print("\t"); Serial.print("bri.: "); Serial.print(brightness); elapsedTime = 0; //Serial.println(" YES led fading! We are between 500 and 2000 ms"); } } if (elapsedTime > 10 && elapsedTime < 500) { ledState = !ledState; if (ledState1) { ledState = !ledState; } elapsedTime = 0; } } //"second" hand if (Sensor.readProximity() < HT ) { startTime = millis(); while (Sensor.readProximity() < HT) { currentTime = millis(); elapsedTime = currentTime - startTime; //Serial.println(elapsedTime); if (elapsedTime > 500) { elapsedTime = 0; //Serial.println("... you missed the window"); if (ledState1) { ledState1 = !ledState1; } } else if (elapsedTime > 10 && elapsedTime < 500) { ledState1 = !ledState1; A = true; //Serial.println(elapsedTimeS); elapsedTime = 0; } } }