Skip to content

Instantly share code, notes, and snippets.

@0rnella
Created March 29, 2022 22:41
Show Gist options
  • Save 0rnella/5986024f1f106f511e75e3c57328ba95 to your computer and use it in GitHub Desktop.
Save 0rnella/5986024f1f106f511e75e3c57328ba95 to your computer and use it in GitHub Desktop.
int strengthMode = 0;
int switchState = 0;
const int TRANSISTOR_PORT = 7;
const int SWITCH_PORT = 6;
const int BLUE_LED_PORT = 5;
const int GREEN_LED_PORT = 4;
const int YELLOW_LED_PORT = 3;
const int RED_LED_PORT = 2;
void setup() {
pinMode(BLUE_LED_PORT, OUTPUT);
pinMode(GREEN_LED_PORT, OUTPUT);
pinMode(YELLOW_LED_PORT, OUTPUT);
pinMode(RED_LED_PORT, OUTPUT);
}
void loop() {
switchState = digitalRead(SWITCH_PORT);
// switch strength on each button press (with debouncing time)
if (switchState == HIGH) {
if (strengthMode <= 5) {
strengthMode++;
delay(200L);
} else {
strengthMode = 0;
delay(200L);
}
}
if (strengthMode == 0) {
// all LEDs off and transistor off
analogWrite(TRANSISTOR_PORT, 0);
digitalWrite(BLUE_LED_PORT, LOW);
digitalWrite(GREEN_LED_PORT, LOW);
digitalWrite(YELLOW_LED_PORT, LOW);
digitalWrite(RED_LED_PORT, LOW);
}
if (strengthMode == 1) {
// blue light, constant vibration
digitalWrite(BLUE_LED_PORT, HIGH);
analogWrite(TRANSISTOR_PORT, 153);
}
if (strengthMode == 2) {
// green light, long alternating vibration
digitalWrite(BLUE_LED_PORT, LOW);
digitalWrite(GREEN_LED_PORT, HIGH);
analogWrite(TRANSISTOR_PORT, 153);
delay(1000);
analogWrite(TRANSISTOR_PORT, 0);
delay(250);
}
if (strengthMode == 3) {
// yellow light, medium alternating vibration
digitalWrite(GREEN_LED_PORT, LOW);
digitalWrite(YELLOW_LED_PORT, HIGH);
analogWrite(TRANSISTOR_PORT, 153);
delay(500);
analogWrite(TRANSISTOR_PORT, 0);
delay(250);
}
if (strengthMode == 4) {
// red light, short alternating vibration
digitalWrite(YELLOW_LED_PORT, LOW);
digitalWrite(RED_LED_PORT, HIGH);
analogWrite(TRANSISTOR_PORT, 153);
delay(250);
analogWrite(TRANSISTOR_PORT, 0);
delay(250);
}
if (strengthMode == 5) {
// all lights, funky pattern vibration
digitalWrite(BLUE_LED_PORT, HIGH);
digitalWrite(GREEN_LED_PORT, HIGH);
digitalWrite(YELLOW_LED_PORT, HIGH);
digitalWrite(RED_LED_PORT, HIGH);
analogWrite(TRANSISTOR_PORT, 153);
delay(500);
analogWrite(TRANSISTOR_PORT, 0);
delay(250);
analogWrite(TRANSISTOR_PORT, 153);
delay(250);
analogWrite(TRANSISTOR_PORT, 0);
delay(250);
analogWrite(TRANSISTOR_PORT, 153);
delay(250);
analogWrite(TRANSISTOR_PORT, 0);
delay(250);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment