-
Notifications
You must be signed in to change notification settings - Fork 0
/
oplà_iot_kit.ino
163 lines (126 loc) · 3.83 KB
/
oplà_iot_kit.ino
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//Tweakly Example for Arduino Oplà IoT Kit
#include "Tweakly.h"
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
//Birthday melody
int birthday[] = {
NOTE_C4,4, NOTE_C4,8,
NOTE_D4,-4, NOTE_C4,-4, NOTE_F4,-4,
NOTE_E4,-2, NOTE_C4,4, NOTE_C4,8,
NOTE_D4,-4, NOTE_C4,-4, NOTE_G4,-4,
NOTE_F4,-2, NOTE_C4,4, NOTE_C4,8,
NOTE_C5,-4, NOTE_A4,-4, NOTE_F4,-4,
NOTE_E4,-4, NOTE_D4,-4, NOTE_AS4,4, NOTE_AS4,8,
NOTE_A4,-4, NOTE_F4,-4, NOTE_G4,-4,
NOTE_F4,-2, 0, 0, NOTE_C4,4, NOTE_C4,8,
NOTE_D4,-4, NOTE_C4,-4, NOTE_F4,-4,
NOTE_E4,-2, NOTE_C4,4, NOTE_C4,8,
NOTE_D4,-4, NOTE_C4,-4, NOTE_G4,-4,
NOTE_F4,-2, NOTE_C4,4, NOTE_C4,8,
NOTE_C5,-4, NOTE_A4,-4, NOTE_F4,-4,
NOTE_E4,-4, NOTE_D4,-4, NOTE_AS4,4, NOTE_AS4,8,
NOTE_A4,-4, NOTE_F4,-4, NOTE_G4,-4,
NOTE_F4,-2, NOTE_END
};
TickTimer clockTimer;
TickTimer greenBlinker;
TickTimer redBlinker;
TickTimer blueBlinker;
TickTimer pwmLed1Timer;
TickTimer pwmLed2Timer;
Pad buzzer(7, MELODY_OUTPUT);
doList changeGreenLedState;
doList changeRedLedState;
doList changeBlueLedState;
doList printTimeText;
Clock myClock;
Player myMelody;
Pong pwmValue1;
Pong pwmValue2;
String timeString;
volatile bool clearTextBool { false };
int greenledstate = 0;
int redledstate = 0;
int blueledstate = 0;
void setup() {
CARRIER_CASE = false;
carrier.begin();
carrier.Buttons.updateConfig(98);
myClock.autoSync();
pwmValue1.setRange(0,255);
pwmValue2.setRange(0,255);
myMelody.buzzerAttach(buzzer.pinNumber());
myMelody.melodyAttach(birthday);
myMelody.setNoteDelay(120);
myMelody.setNoteDuration(40);
myMelody.repeat(false);
carrier.display.setRotation(4);
carrier.display.fillScreen(ST77XX_WHITE);
carrier.display.fillScreen(ST77XX_WHITE);
carrier.display.setTextSize(2);
carrier.display.setCursor(40, 60);
carrier.display.setTextColor(ST77XX_BLACK);
carrier.display.print("Easy, Tweakly!");
carrier.display.setCursor(34,105);
carrier.display.setTextColor(ST77XX_BLACK);
carrier.display.print("Beta 2 is here!");
carrier.display.setTextSize(3);
changeGreenLedState.addTask([] { greenledstate = 255;});
changeGreenLedState.addTask([] { greenledstate = 0;});
changeRedLedState.addTask([] { redledstate = 255;});
changeRedLedState.addTask([] { redledstate = 0;});
changeBlueLedState.addTask([] { blueledstate = 255;});
changeBlueLedState.addTask([] { blueledstate = 0;});
printTimeText.addTask([] {
timeString = stringAssembler("%d:%d:%d", myClock.getHours(), myClock.getMinutes(), myClock.getSeconds());
carrier.display.setTextColor(ST77XX_BLACK);
carrier.display.print(timeString);
});
printTimeText.addTask([] {
carrier.display.setTextColor(ST77XX_WHITE);
carrier.display.print(timeString);
});
pwmLed1Timer.attach(10,[] {
carrier.leds.setPixelColor(3, 0,pwmValue1.value(),0);
carrier.leds.show();
});
pwmLed2Timer.attach(1,[] {
carrier.leds.setPixelColor(4, 0,pwmValue2.value(),0);
carrier.leds.show();
});
clockTimer.attach(500, [] {
carrier.display.setCursor(55, 80);
printTimeText++;
});
greenBlinker.attach(250, [] {
carrier.leds.setPixelColor(0, greenledstate,0,0);
carrier.leds.show();
changeGreenLedState++;
});
redBlinker.attach(1000, [] {
carrier.leds.setPixelColor(1, 0,redledstate,0);
carrier.leds.show();
changeRedLedState++;
});
blueBlinker.attach(1500, [] {
carrier.leds.setPixelColor(2, 0,0,blueledstate);
carrier.leds.show();
changeBlueLedState++;
});
}
void loop() {
TweaklyRun();
carrier.Buttons.update();
if(carrier.Buttons.getTouch(TOUCH3)) {
myMelody.play();
Serial.println("play pressed");
}
if(carrier.Buttons.getTouch(TOUCH1)) {
myMelody.pause();
Serial.println("pause pressed");
}
if(carrier.Buttons.getTouch(TOUCH2)) {
myMelody.stop();
Serial.println("stop pressed");
}
}