Skip to content

Instantly share code, notes, and snippets.

@bacalj
Last active November 9, 2022 19:35
Show Gist options
  • Save bacalj/975f730cf4cb8c08a2d3d6aec154b8ac to your computer and use it in GitHub Desktop.
Save bacalj/975f730cf4cb8c08a2d3d6aec154b8ac to your computer and use it in GitHub Desktop.
Copied from downloaded sketch from Backyard Brains help site: https://backyardbrains.com/experiments/muscleSpikerShield
#define NUM_LED 6 //sets the maximum numbers of LEDs
#define MAX 150 //maximum posible reading. TWEAK THIS VALUE!!
int reading[10];
int finalReading;
byte litLeds = 0;
byte multiplier = 1;
byte leds[] = {8, 9, 10, 11, 12, 13};
void setup(){
Serial.begin(9600); //begin serial communications
for(int i = 0; i < NUM_LED; i++){ //initialize LEDs as outputs
pinMode(leds[i], OUTPUT);
}
}
void loop(){
for(int i = 0; i < 10; i++){ //take ten readings in ~0.02 seconds
reading[i] = analogRead(A0) * multiplier;
delay(2);
}
for(int i = 0; i < 10; i++){ //average the ten readings
finalReading += reading[i];
}
finalReading /= 10;
for(int j = 0; j < NUM_LED; j++){ //write all LEDs low
digitalWrite(leds[j], LOW);
}
Serial.print(finalReading);
Serial.print("\t");
finalReading = constrain(finalReading, 0, MAX);
litLeds = map(finalReading, 0, MAX, 0, NUM_LED);
Serial.println(litLeds);
for(int k = 0; k < litLeds; k++){
digitalWrite(leds[k], HIGH);
}
//for serial debugging, uncomment the next two lines.
//Serial.println(finalReading);
//delay(100);
//url test
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment