Created
September 22, 2013 07:52
-
-
Save swarut/6657753 to your computer and use it in GitHub Desktop.
Code from arduino class.
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
// Communication is done by ansci | |
const int FIRST_ON = '0'; | |
const int SECOND_ON = '1'; | |
const int ALL_ON = '2'; | |
const int ALL_OFF = '3'; | |
boolean stop = false; | |
struct led{ | |
int delayLength; | |
int pinNumber; | |
int numberOfLoop; | |
}; | |
void setup() { | |
pinMode(4, OUTPUT); | |
pinMode(5, OUTPUT); | |
// Serial.begin(9600); | |
} | |
void loop() { | |
struct led myLed; | |
myLed.delayLength = 1000; | |
myLed.pinNumber = 4; | |
myLed.numberOfLoop = 3; | |
blinkFor(myLed); | |
} | |
void serialListen(void) { | |
if (Serial.available() > 0) { | |
Serial.print("\nready\n"); | |
int input = Serial.read(); | |
Serial.write("read :"); | |
Serial.write(input); | |
Serial.write("\n"); | |
if (input == FIRST_ON){ | |
Serial.print("first on"); | |
turnLightOff(5); | |
blinkLight(4); | |
} | |
else if (input == SECOND_ON) { | |
Serial.print("second on"); | |
turnLightOff(4); | |
blinkLight(5); | |
} | |
else if (input == ALL_ON) { | |
Serial.print("all on"); | |
blinkLight(4); | |
blinkLight(5); | |
} | |
else { | |
Serial.print(FIRST_ON); | |
turnLightOff(4); | |
turnLightOff(5); | |
} | |
} | |
} | |
void blinkLight(int ledNO) { | |
digitalWrite(ledNO, HIGH); | |
} | |
void turnLightOff(int ledNO) { | |
digitalWrite(ledNO, LOW); | |
} | |
void blinkFor(struct led myLed) { | |
if (!stop){ | |
for (int i = 0; i < myLed.numberOfLoop; i++) { | |
blinkLight(myLed.pinNumber); | |
delay(myLed.delayLength); | |
turnLightOff(myLed.pinNumber); | |
delay(myLed.delayLength); | |
} | |
stop = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment