Skip to content

Instantly share code, notes, and snippets.

@sjurlur
Last active December 14, 2015 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjurlur/5116345 to your computer and use it in GitHub Desktop.
Save sjurlur/5116345 to your computer and use it in GitHub Desktop.
Den bråkete apekatten
const int M1 = 4; // H-bridge leg 1 (pin 2, 1A)
const int E1 = 5;
const int M2 = 8; // H-bridge leg 2 (pin 7, 2A)
const int E2 = 9;
const int mouthPin = 2;
//const int knapp = 3;
char mouth;
boolean state = true;
const int enablePin = 10; // H-bridge enable pin
void setup() {
Serial.begin(9600);
// set all the other pins you're using as outputs:
pinMode(M1, OUTPUT);
pinMode(M2, OUTPUT);
pinMode(enablePin, OUTPUT);
pinMode(mouthPin, INPUT);
//pinMode(knapp, INPUT);
attachInterrupt(0, mouthTrigger, RISING);
attachInterrupt(1, knappTrigger, RISING);
// set enablePin high so that motor can turn on:
analogWrite(enablePin, 225);
}
void loop() {
//Serial.println(state);
//Serial.println(digitalRead(knapp));
if(Serial.available()){
if(Serial.read() == 75){
state = false;
}
}
if (!state) {
Serial.println("false");
digitalWrite(M1, HIGH); // set leg 1 of the H-bridge high
digitalWrite(M2, LOW); // set leg 2 of the H-bridge low
}
else {
Serial.println("true");
digitalWrite(M1, LOW); // set leg 1 of the H-bridge low
digitalWrite(M2, HIGH); // set leg 2 of the H-bridge high
//delay(2500);
}
delay(100);
}
void mouthTrigger() {
state = true;
}
void knappTrigger(){
state = false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment