From 2f89a12ba85cd71b266c5b7c0a563ab81b3cb474 Mon Sep 17 00:00:00 2001 From: NoOne2246 Date: Mon, 16 May 2016 16:07:03 +1000 Subject: [PATCH 1/3] Initial Bounce code to test This code introduces a 20 cycle delay so if it was pressed in the last 20 cycles (1 cycle = read every sensor once), then it won't read that sensor. --- Sensor_Reader/Sensor_Reader.ino | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Sensor_Reader/Sensor_Reader.ino b/Sensor_Reader/Sensor_Reader.ino index 1d82948..f0982b6 100644 --- a/Sensor_Reader/Sensor_Reader.ino +++ b/Sensor_Reader/Sensor_Reader.ino @@ -1,10 +1,11 @@ /*-- Define Pins --*/ #define LIM 1015 //The point at which the sensor switches between touch and release -#define BOUNCE 30 +#define BOUNCE 20 //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 --*/ @@ -12,6 +13,7 @@ void setup() { 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 --*/ @@ -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); } From f193fa9027089b8dd0d50a42e5fe4ed0c2703e57 Mon Sep 17 00:00:00 2001 From: NoOne2246 Date: Tue, 17 May 2016 20:40:21 +1000 Subject: [PATCH 2/3] Debounce Working Only thing that really needs to change now is to ensure that the sensitivity is fixed, don't know if we need to change the sensitivity/adjust for each sensor. --- Sensor_Reader/Sensor_Reader.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sensor_Reader/Sensor_Reader.ino b/Sensor_Reader/Sensor_Reader.ino index f0982b6..5a178f5 100644 --- a/Sensor_Reader/Sensor_Reader.ino +++ b/Sensor_Reader/Sensor_Reader.ino @@ -1,6 +1,6 @@ /*-- Define Pins --*/ #define LIM 1015 //The point at which the sensor switches between touch and release -#define BOUNCE 20 //Number of Cycles to debounce +#define BOUNCE 1000 //Number of Cycles to debounce /*-- Set up Variables --*/ boolean States[16]; //set states to off @@ -32,7 +32,7 @@ void loop() { } else { //If there is no pressure States[i] = false; //Change state to untouched } - }else if(Bounce[i]>1){ + }else if(Bounce[i]>= 1){ Bounce[i] = Bounce[i] - 1; } } From 9ee63a864313b453176127ef67f34ba9c23a9a5f Mon Sep 17 00:00:00 2001 From: NoOne2246 Date: Thu, 19 May 2016 16:13:48 +1000 Subject: [PATCH 3/3] Changed to 400 got a problem with sensitivity on one of the sides, may require a custom mapping of pins and sensitivity --- Sensor_Reader/Sensor_Reader.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sensor_Reader/Sensor_Reader.ino b/Sensor_Reader/Sensor_Reader.ino index 5a178f5..5b808a9 100644 --- a/Sensor_Reader/Sensor_Reader.ino +++ b/Sensor_Reader/Sensor_Reader.ino @@ -1,6 +1,6 @@ /*-- Define Pins --*/ #define LIM 1015 //The point at which the sensor switches between touch and release -#define BOUNCE 1000 //Number of Cycles to debounce +#define BOUNCE 400 //Number of Cycles to debounce /*-- Set up Variables --*/ boolean States[16]; //set states to off