Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
boitarire
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Flax
boitarire
Commits
5df78294
Commit
5df78294
authored
Nov 25, 2021
by
Flax
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SW : added touch sensors management.
parent
0587b365
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
10 deletions
+37
-10
sw/boitarire_sw/boitarire_sw.ino
sw/boitarire_sw/boitarire_sw.ino
+37
-10
No files found.
sw/boitarire_sw/boitarire_sw.ino
View file @
5df78294
...
...
@@ -19,12 +19,14 @@
// Defines - Macros - Constants
#define SENSOR_INCLINATION
#define SENSOR_ACCELEROMETER
#define SENSOR_TOUCHSENSOR1
#define SENSOR_TOUCHSENSOR2
#define SENSOR_TOUCH
_
SENSOR1
#define SENSOR_TOUCH
_
SENSOR2
//#define MP3_RESET
// Other constants
#define PIN_SENSOR_POSITION 9 // Position sensor input
#define PIN_TOUCH_SENSOR1 8 // Touch sensor 1 input
#define PIN_TOUCH_SENSOR2 5 // Touch sensor 2 input
#define PIN_GROUND_SWITCH 7 // MP3 module ground switch command output
#define PLAY_BLANK_DELAY 1000 // Blanking when playing a sound (ms)
#define DELAY_MP3_RESET 100 // Time of ground cut of MP3 module for re-init (ms)
...
...
@@ -56,7 +58,7 @@ String inputString = ""; // a String to hold incoming data
bool
stringComplete
=
false
;
// whether the string is complete
unsigned
long
debounce_delay
;
bool
input_now
;
int
input_position_sensor
,
input_touch_sensor1
,
input_touch_sensor2
;
unsigned
long
play_blank_delay
,
mp3_reset_delay
;
// State machines states
...
...
@@ -77,6 +79,12 @@ void setup() {
// Position sensor input pin - D9 - Input pull-up
pinMode
(
PIN_SENSOR_POSITION
,
INPUT_PULLUP
);
// Touch sensor 1 input pin - D8 - Input no pull
pinMode
(
PIN_TOUCH_SENSOR1
,
INPUT
);
// Touch sensor 2 input pin - D5 - Input no pull
pinMode
(
PIN_TOUCH_SENSOR2
,
INPUT
);
// LED output for visualisation
pinMode
(
LED_BUILTIN
,
OUTPUT
);
...
...
@@ -88,7 +96,9 @@ void setup() {
stmState
=
STM_INIT
;
stmDebounceState
=
STM_DEBOUNCE_IDLE_0
;
debounce_delay
=
0
;
input_now
=
0
;
input_position_sensor
=
LOW
;
input_touch_sensor1
=
LOW
;
input_touch_sensor2
=
LOW
;
// Connect ground for MP3 module
digitalWrite
(
PIN_GROUND_SWITCH
,
HIGH
);
...
...
@@ -116,9 +126,9 @@ void loop() {
#ifdef SENSOR_INCLINATION
// Read instantaneous value of position sensor
input_
now
=
digitalRead
(
PIN_SENSOR_POSITION
);
input_
position_sensor
=
digitalRead
(
PIN_SENSOR_POSITION
);
#else
input_
now
=
0
;
input_
position_sensor
=
LOW
;
#endif
// Inclination debounce state machine
...
...
@@ -126,7 +136,7 @@ void loop() {
switch
(
stmDebounceState
)
{
case
STM_DEBOUNCE_IDLE_0
:
if
(
input_
now
==
1
)
if
(
input_
position_sensor
==
HIGH
)
{
stmDebounceState
=
STM_DEBOUNCE_DETECT_1
;
debounce_delay
=
millis
();
...
...
@@ -134,7 +144,7 @@ void loop() {
break
;
case
STM_DEBOUNCE_IDLE_1
:
if
(
input_
now
==
0
)
if
(
input_
position_sensor
==
LOW
)
{
stmDebounceState
=
STM_DEBOUNCE_DETECT_0
;
debounce_delay
=
millis
();
...
...
@@ -142,7 +152,7 @@ void loop() {
break
;
case
STM_DEBOUNCE_DETECT_0
:
if
(
input_
now
==
1
)
if
(
input_
position_sensor
==
HIGH
)
{
stmDebounceState
=
STM_DEBOUNCE_IDLE_1
;
}
...
...
@@ -153,7 +163,7 @@ void loop() {
break
;
case
STM_DEBOUNCE_DETECT_1
:
if
(
input_
now
==
0
)
if
(
input_
position_sensor
==
LOW
)
{
stmDebounceState
=
STM_DEBOUNCE_IDLE_0
;
}
...
...
@@ -176,6 +186,18 @@ void loop() {
default:
break
;
}
#ifdef SENSOR_TOUCH_SENSOR1
input_touch_sensor1
=
digitalRead
(
PIN_TOUCH_SENSOR1
);
#else
input_touch_sensor1
=
LOW
;
#endif
#ifdef SENSOR_TOUCH_SENSOR2
input_touch_sensor2
=
digitalRead
(
PIN_TOUCH_SENSOR2
);
#else
input_touch_sensor2
=
LOW
;
#endif
// Main state machine
//-------------------
...
...
@@ -190,6 +212,11 @@ void loop() {
{
stmState
=
STM_PLAY
;
}
if
((
input_touch_sensor1
==
HIGH
)
|
(
input_touch_sensor2
==
HIGH
))
{
stmState
=
STM_PLAY
;
}
break
;
case
STM_PLAY
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment