Skip to content

Instantly share code, notes, and snippets.

@Craigson
Created September 15, 2014 02:00
Show Gist options
  • Save Craigson/83f41471c694bf58206e to your computer and use it in GitHub Desktop.
Save Craigson/83f41471c694bf58206e to your computer and use it in GitHub Desktop.
The Love-o-meter: Under pressure
//Love-o-meter: under pressure
//Craig Pickard
//this is an indicator level with 6 stages, the first stage has four levels
//with green LEDs, the highest two levels use red LEDs to indicate danger
const int levelOne = 5; //green LED
const int levelTwo = 6; //green LED
const int levelThree = 7; //green LED
const int levelFour = 8; //green LED
const int levelFive = 9; //green LED
const int levelSix = 10; //green LED
int FSRvalue = 0; //create and initalise a variable for reading the LSR
void setup(){
Serial.begin(9600);
//define output pins
pinMode(levelOne, OUTPUT);
pinMode(levelTwo, OUTPUT);
pinMode(levelThree, OUTPUT);
pinMode(levelFour, OUTPUT);
pinMode(levelFive, OUTPUT);
pinMode(levelSix, OUTPUT);
}
void loop(){
FSRvalue = analogRead(A0); //read the value of the FSR
int level = map(FSRvalue, 0, 1000,0,6); //map the FSR reading to the 6 levels of the indicator bar
if(FSRvalue > 960){
digitalWrite(levelOne, HIGH);
digitalWrite(levelTwo, HIGH);
digitalWrite(levelThree,HIGH);
digitalWrite(levelFour,HIGH);
digitalWrite(levelFive,HIGH);
digitalWrite(levelSix,HIGH);
}
else if (FSRvalue > 920 && FSRvalue < 970) {
digitalWrite(levelOne, HIGH);
digitalWrite(levelTwo, HIGH);
digitalWrite(levelThree,HIGH);
digitalWrite(levelFour,HIGH);
digitalWrite(levelFive,HIGH);
}
else if (FSRvalue > 800 && FSRvalue < 920) {
digitalWrite(levelOne, HIGH);
digitalWrite(levelTwo, HIGH);
digitalWrite(levelThree,HIGH);
digitalWrite(levelFour,HIGH);
}
else if (FSRvalue > 600 && FSRvalue < 800) {
digitalWrite(levelOne, HIGH);
digitalWrite(levelTwo, HIGH);
digitalWrite(levelThree,HIGH);
}
else if (FSRvalue > 400 && FSRvalue < 600) {
digitalWrite(levelOne, HIGH);
digitalWrite(levelTwo, HIGH);
}
else if (FSRvalue > 50 && FSRvalue < 400) {
digitalWrite(levelOne, HIGH);
}else{
digitalWrite(levelOne,LOW);
digitalWrite(levelTwo,LOW);
digitalWrite(levelThree,LOW);
digitalWrite(levelFour,LOW);
digitalWrite(levelFive,LOW);
digitalWrite(levelSix,LOW);
}
Serial.print("Your love-strength level is: ");
Serial.println(level);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment