-
-
Save melPlett/b2b248c19e86bfb3a7c90e6ad84719a6 to your computer and use it in GitHub Desktop.
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 upPin = A0; // select analog input pins for the pressure sensors | |
int downPin = A1; | |
int up; // declare variables to store the values coming from the sensors | |
int down; | |
int pump = 8; //this pin is named to keep track of which pin the air pump is on | |
int level; //declare variable to track the selected level | |
void setup() { | |
Serial.begin(9600); | |
// setup pins to be inputs or outputs | |
pinMode(1, OUTPUT); | |
pinMode(2, OUTPUT); | |
pinMode(3, OUTPUT); | |
// for pins controlling solenoid valves, HIGH means the valve is closed and not letting air through, | |
//for the pump, HIGH means it is on and pumping air into the system. | |
digitalWrite(1, HIGH); | |
digitalWrite(2, HIGH); | |
digitalWrite(3, HIGH); | |
digitalWrite(pump, LOW); | |
level = 0; //set the "score" of the level to 0 to start | |
} | |
void loop() { | |
up= analogRead(upPin); | |
down = analogRead(downPin); | |
Serial.println(up); | |
Serial.println(down); | |
// calculate current level and set the bounds of the levels so that the "level" is | |
//always a number that aligns with one of the defined states | |
if (up >= 10) { | |
level = (level +1); | |
delay(500); | |
} | |
if (down >= 10) { | |
level = (level - 1); | |
delay(500); | |
} | |
if (level < 0) { | |
level = 0; | |
} | |
if (level > 3) { | |
level = 3; | |
} | |
Serial.print("level = "); | |
Serial.println(level); | |
//inflate pouches for visual and tactile level indication | |
if (level == 1) { | |
digitalWrite(pump, HIGH); | |
digitalWrite(1, LOW); | |
digitalWrite(2, HIGH); | |
digitalWrite(3, HIGH); | |
} | |
else if (level == 2) { | |
digitalWrite(pump, HIGH); | |
digitalWrite(1, LOW); | |
digitalWrite(2, LOW); | |
digitalWrite(3, HIGH); | |
} | |
else if (level == 3) { | |
digitalWrite(pump, HIGH); | |
digitalWrite(1, LOW); | |
digitalWrite(2, LOW); | |
digitalWrite(3, LOW); | |
} | |
else { | |
digitalWrite(pump, LOW); | |
digitalWrite(1, HIGH); | |
digitalWrite(2, HIGH); | |
digitalWrite(3, HIGH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment