Created
February 23, 2012 14:44
-
-
Save katsyoshi/1893139 to your computer and use it in GitHub Desktop.
listen grep tool for arduino
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 beatPin = 3; | |
int baudRate = 9600; | |
int ledPin[] = {6,7,8,9,10,11,12,13}; | |
void ledOn(int num){ | |
for(int i = 0; i < 8; i++){ | |
if(bitRead(num,i)==1){ | |
digitalWrite(ledPin[i], HIGH); | |
} | |
} | |
for(int i = 0; i < 8; i++){ | |
digitalWrite(ledPin[i], LOW); | |
} | |
} | |
void setup(){ | |
Serial.begin(baudRate); | |
pinMode(beatPin, OUTPUT); | |
for(int num = 0; num < 8; num++){ | |
pinMode(ledPin[num], OUTPUT); | |
} | |
} | |
int incomingByte = 0; | |
void loop(){ | |
if( Serial.available() > 0 ){ | |
incomingByte = Serial.read(); | |
int frequency = incomingByte * 10 + 40; | |
Serial.println(incomingByte); | |
ledOn(incomingByte); | |
tone(beatPin, frequency); | |
}else{ | |
noTone(beatPin); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment