Skip to content

Instantly share code, notes, and snippets.

@archmangler
Created June 11, 2020 12:41
Show Gist options
  • Save archmangler/1c4e9ddd044f1026ec5da921ddc70f91 to your computer and use it in GitHub Desktop.
Save archmangler/1c4e9ddd044f1026ec5da921ddc70f91 to your computer and use it in GitHub Desktop.
Basic Impact Detection for Motor Drive

int LEDs[] = {23,22,19,18};

#define Button1 32 #define Button2 33 #define Button3 34 #define Button4 35

#define UP 0 #define DOWN 1

#define ON HIGH #define OFF LOW

unsigned char Button_State;

void setup() { unsigned char i; for (i=0; i<=3; i++) { pinMode(LEDs[i], OUTPUT); digitalWrite(LEDs[i],OFF); }

pinMode(Button1, INPUT);

pinMode(Button2, INPUT);

pinMode(Button3, INPUT);

pinMode(Button4, INPUT);

}

void loop() {

unsigned char j; //LED 0: Rear Right //LED 1: Front Right //LED 2: Front Left //LED 3: Rear Left

delay(500); digitalWrite(LEDs[1],ON); digitalWrite(LEDs[2],ON); delay(500); digitalWrite(LEDs[1],OFF); digitalWrite(LEDs[2],OFF); delay(1000);

Button_State = digitalRead(Button1);

if(Button_State == UP) { //Do nothing } else if(Button_State == DOWN) { digitalWrite(LEDs[0],ON); digitalWrite(LEDs[3],ON); delay(500); digitalWrite(LEDs[0],OFF); digitalWrite(LEDs[3],OFF); delay(500); digitalWrite(LEDs[0],ON); digitalWrite(LEDs[2],ON); delay(500); digitalWrite(LEDs[0],OFF); digitalWrite(LEDs[2],OFF);

}

Button_State = digitalRead(Button2);

if(Button_State == UP) { //Do nothing } else if(Button_State == DOWN) { digitalWrite(LEDs[0],ON); digitalWrite(LEDs[3],ON); delay(500); digitalWrite(LEDs[0],OFF); digitalWrite(LEDs[3],OFF); delay(500); digitalWrite(LEDs[0],ON); digitalWrite(LEDs[2],ON); delay(500); digitalWrite(LEDs[0],OFF); digitalWrite(LEDs[2],OFF);

}

Button_State = digitalRead(Button3); if(Button_State == UP) { //Do nothing } else if(Button_State == DOWN) { digitalWrite(LEDs[0],ON); digitalWrite(LEDs[3],ON); delay(500); digitalWrite(LEDs[0],OFF); digitalWrite(LEDs[3],OFF); delay(500); digitalWrite(LEDs[0],ON); digitalWrite(LEDs[2],ON); delay(500); digitalWrite(LEDs[0],OFF); digitalWrite(LEDs[2],OFF);

}

Button_State = digitalRead(Button4);

if(Button_State == UP) { //Do nothing } else if(Button_State == DOWN) { digitalWrite(LEDs[0],ON); digitalWrite(LEDs[3],ON); delay(500); digitalWrite(LEDs[0],OFF); digitalWrite(LEDs[3],OFF); delay(500); digitalWrite(LEDs[0],ON); digitalWrite(LEDs[2],ON); delay(500); digitalWrite(LEDs[0],OFF); digitalWrite(LEDs[2],OFF);

} }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment