Concept & Inspiration.
For this small project, I was thinking of making something feasible to construct yet useful for me. As I was almost lying on the chair after barely 5 minutes in the IM Lab, it didn’t take me long to come up with an idea of a switch that would regulate posture and indicate how well the person is seated (a so-called “posture fixer”) by using the LED lights, a regular paper tape, and conductive fabric.
Highlights.
I set two variables (“yellowState” and “greenState”) in my code to regulate the LED switches by using the “if” condition functions.
My main goal was to make the LED lights react accordingly to a certain number of “buttons” pressed. For instance, when no button is pressed, the red LED is blinking as a sign of warning. When only one of the buttons is pressed (either green or yellow), the yellow sign is switched on, meaning that the posture is satisfactory yet not perfect. In case if both buttons are pressed, green LED is switched on, indicating decent posture.
if (yellowState == HIGH && greenState == HIGH) { // When both buttons pressed digitalWrite(4, HIGH); // Turn on green LED digitalWrite(2, LOW); // Turn off yellow LED digitalWrite(LED_BUILTIN, LOW); // Turn off red LED } else if (yellowState == HIGH || greenState == HIGH) { // When only one button pressed digitalWrite(4, LOW); // Turn off green LED digitalWrite(2, HIGH); // Turn on yellow LED digitalWrite(LED_BUILTIN, LOW); // Turn off red LED } else { // When no button is pressed digitalWrite(4, LOW); // Turn off green LED digitalWrite(2, LOW); // Turn off yellow LED digitalWrite(LED_BUILTIN, HIGH); // Blinking red LED (for 1 second) delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); } }
Embedded Sketch.