Skip to content

Instantly share code, notes, and snippets.

@katsyoshi
Created February 23, 2012 14:44
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 katsyoshi/1893139 to your computer and use it in GitHub Desktop.
Save katsyoshi/1893139 to your computer and use it in GitHub Desktop.
listen grep tool for arduino
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