-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSetButtonLED.java
More file actions
57 lines (44 loc) · 1.72 KB
/
SetButtonLED.java
File metadata and controls
57 lines (44 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import grovepi.GrovePi;
import grovepi.Pin;
import grovepi.sensors.*;
/**
This program turns on the LED for the selected event type and turns it off for the rest.
This is done as feedback to users when they select an event type.
**/
class SetButtonLED {
int selection = 0;
public static void main(String[] args) {
GrovePi grovePi = new GrovePi();
ButtonSensor foodBtn = grovePi.getDeviceFactory().createButtonSensor(Pin.DIGITAL_PIN_1);
ButtonSensor drinksBtn = grovePi.getDeviceFactory().createButtonSensor(Pin.DIGITAL_PIN_2);
ButtonSensor chillBtn = grovePi.getDeviceFactory().createButtonSensor(Pin.DIGITAL_PIN_3);
Led foodLED = grovePi.getDeviceFactory().createLed(Pin.DIGITAL_PIN_4);
Led drinksLED = grovePi.getDeviceFactory().createLed(Pin.DIGITAL_PIN_5);
Led chillLED = grovePi.getDeviceFactory().createLed(Pin.DIGITAL_PIN_6);
//run the program forever
while(true) {
//enable LED for button that is pressed
if(foodBtn.isPressed()) {
foodLED.setState(true);
drinksLED.setState(false);
chillLED.setState(false);
selection = 0;
}
if(drinksBtn.isPressed()) {
foodLED.setState(false);
drinksLED.setState(true);
chillLED.setState(false);
selection = 1;
}
if(chillBtn.isPressed()) {
foodLED.setState(false);
drinksLED.setState(false);
chillLED.setState(true);
selection = 2;
}
}
}
public int returnSelection {
return selection;
}
}