Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions Sensor_Reader/Sensor_Reader.ino
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/*-- Define Pins --*/
#define LIM 1015 //The point at which the sensor switches between touch and release
#define BOUNCE 30
#define BOUNCE 400 //Number of Cycles to debounce

/*-- Set up Variables --*/
boolean States[16]; //set states to off
int Pins[16] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15};
int Bounce[16];

void setup() {
/*-- Set Analog Pins --*/
for (int i = 0; i < 16; i++){
pinMode(Pins[i], INPUT); //set analog pins for input
digitalWrite(Pins[i], HIGH); //Pull up analog pins
States[i] = false;
Bounce[i] = 0;
}

/*-- Set up Serial --*/
Expand All @@ -20,14 +22,18 @@ void setup() {

void loop() {
for(int i = 0; i < 16; i++){ //cycle through pins
if(analogRead(Pins[i]) < LIM){ //Check if the sensor has detected touch
if(States[i] != true){ //If sensor has detected touch, was it previously being touched, if not:
States[i] = true; //Set up so that it's state is being touched
Serial.println(i+1); //Send information on pin touched
if(Bounce[i]<1){
if(analogRead(Pins[i]) < LIM){ //Check if the sensor has detected touch
if(States[i] != true){ //If sensor has detected touch, was it previously being touched, if not:
States[i] = true; //Set up so that it's state is being touched
Serial.println(i+1); //Send information on pin touched
Bounce[i] = BOUNCE;
}
} else { //If there is no pressure
States[i] = false; //Change state to untouched
}
} else { //If there is no pressure
States[i] = false; //Change state to untouched
}else if(Bounce[i]>= 1){
Bounce[i] = Bounce[i] - 1;
}
}
delay(BOUNCE);
}