File tree Expand file tree Collapse file tree 1 file changed +24
-18
lines changed Expand file tree Collapse file tree 1 file changed +24
-18
lines changed Original file line number Diff line number Diff line change 1
- #include " Braccio++.h"
1
+ #include < Braccio++.h>
2
2
3
- String message = " " ;
3
+ String toMessage (int const input)
4
+ {
5
+ static String const message[] =
6
+ { " " ,
7
+ " LEFT (Joystick)" ,
8
+ " RIGHT (Joystick)" ,
9
+ " SELECT (Joystick)" ,
10
+ " UP (Joystick)" ,
11
+ " DOWN (Joystick)" ,
12
+ " ENTER (Button)"
13
+ };
4
14
5
- String checkInputs (int input){
6
- String check[] = { " " ,
7
- " Joystick left was moved!" ,
8
- " Joystick right was moved!" ,
9
- " Joystick select button was pressed!" ,
10
- " Joystick up was moved!" ,
11
- " Joystick down was moved!" ,
12
- " Enter button was pressed!" };
13
- return check[input];
15
+ if (input < 7 )
16
+ return message[input];
17
+ else
18
+ return String (" Error, invalid input value" );
14
19
}
15
20
16
- void setup () {
21
+ void setup ()
22
+ {
17
23
Serial.begin (115200 );
18
24
while (!Serial){}
25
+
19
26
Braccio.begin ();
20
27
Serial.println (" Press any button or move the joystick." );
21
28
}
22
29
23
- void loop () {
24
- message = checkInputs (Braccio.getKey ());
25
- if (message != " " ){
30
+ void loop ()
31
+ {
32
+ String const message = toMessage (Braccio.getKey ());
33
+ if (message != " " )
26
34
Serial.println (message);
27
- message = " " ;
28
- }
29
- delay (500 );
35
+ delay (100 );
30
36
}
You can’t perform that action at this time.
0 commit comments