Created
June 10, 2019 08:56
-
-
Save e-Gizmo/f019170137e2e35140e288006bedf4ef to your computer and use it in GitHub Desktop.
This is one of the example codes for FireFighterFan.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int DCMOTOR = 4; | |
int PWM_SPEED = 100; | |
int SPEED_MOTOR = 150; | |
boolean fire = false; | |
void setup() { | |
// put your setup code here, to run once: | |
Serial.begin(9600); | |
// DC MOTOR | |
pinMode(DCMOTOR, OUTPUT); | |
// FLAME SENSORS | |
pinMode(5, INPUT); //FS_RIGHT | |
pinMode(6, INPUT); //FS_CENTER | |
pinMode(7, INPUT); //FS_LEFT | |
//MOTOR PINS | |
pinMode(8, OUTPUT); //dirmotor1 | |
pinMode(9, OUTPUT); //spdmotor1 | |
pinMode(10, OUTPUT); //spdmotor2 | |
pinMode(11, OUTPUT); //dirmotor2 | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
int FLAME_RIGHT = digitalRead(5); | |
int FLAME_CENTER = digitalRead(6); | |
int FLAME_LEFT = digitalRead(7); | |
if (FLAME_RIGHT == 0 || FLAME_LEFT == 0) | |
{ | |
fire = true; | |
} | |
while (fire == true) { | |
PUT_OFF_FIRE(); | |
} | |
delay(10); | |
} | |
void PUT_OFF_FIRE() { | |
int FLAME_RIGHT = digitalRead(5); | |
int FLAME_CENTER = digitalRead(6); | |
int FLAME_LEFT = digitalRead(7); | |
if (FLAME_CENTER == 0) { | |
FORWARD(); | |
delay(500); | |
} | |
else if (FLAME_RIGHT == 0) { | |
TURN_RIGHT(); | |
delay(500); | |
} | |
else if (FLAME_LEFT == 0) { | |
TURN_LEFT(); | |
delay(500); | |
} | |
STOP(); | |
delay(1000); | |
// digitalWrite(RELAY_DC, HIGH); | |
digitalWrite(DCMOTOR, HIGH); | |
delay(5000); | |
digitalWrite(DCMOTOR, LOW); | |
delay(1000); | |
fire = false; | |
} | |
void FORWARD() { | |
digitalWrite(8, HIGH); | |
analogWrite(9, SPEED_MOTOR); | |
analogWrite(10, SPEED_MOTOR); | |
digitalWrite(11, HIGH); | |
} | |
void TURN_RIGHT() { | |
digitalWrite(8, HIGH); | |
analogWrite(9, SPEED_MOTOR); | |
analogWrite(10, SPEED_MOTOR); | |
digitalWrite(11, LOW); | |
} | |
void TURN_LEFT() { | |
digitalWrite(8, LOW); | |
analogWrite(9, SPEED_MOTOR); | |
analogWrite(10, SPEED_MOTOR); | |
digitalWrite(11, HIGH); | |
} | |
void STOP() { | |
//digitalWrite(8, HIGH); | |
analogWrite(9, 0); | |
analogWrite(10, 0); | |
//digitalWrite(11, HIGH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment