Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int fanPin = 3;
- int incomingByte[2];
- boolean FAN = false;
- //Waits for 'L1' and 'L2' to be received via COM**
- //L1 = ON
- //L2 = OFF
- void setup()
- {
- pinMode(fanPin, OUTPUT);
- digitalWrite(fanPin, LOW);
- Serial.begin(19200);
- }
- void loop()
- {
- if (Serial.available() > 0)
- {
- while (Serial.peek() == 'L')
- {
- Serial.read();
- incomingByte[0] = Serial.parseInt();
- if(incomingByte[0] == 1)
- {
- FAN = true;
- //Serial.write("HI");
- }
- else
- {
- FAN = false;
- //Serial.write("LOW");
- }
- }
- while (Serial.available() > 0)
- {
- Serial.read();
- }
- FanCheck();
- }
- }
- void FanCheck()
- {
- if (FAN)
- {
- digitalWrite(fanPin, HIGH);
- }
- else
- {
- digitalWrite(fanPin, LOW);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement