Skip to content

Commit 48f3e2d

Browse files
authored
Merge pull request #10 from bcmi-labs/changes
Changes
2 parents 283bce4 + f9a2f30 commit 48f3e2d

File tree

21 files changed

+1480
-0
lines changed

21 files changed

+1480
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Melody
3+
4+
Adapted for the Arduino MKR IoT Carrier
5+
6+
*/
7+
#include <Arduino_MKRIoTCarrier.h>
8+
#include "pitches.h"
9+
10+
MKRIoTCarrier carrier;
11+
bool CARRIER_CASE = false;
12+
13+
// notes in the melody:
14+
int melody[] = {
15+
NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
16+
};
17+
18+
// note durations: 4 = quarter note, 8 = eighth note, etc.:
19+
int noteDurations[] = {
20+
4, 8, 8, 4, 4, 4, 4, 4
21+
};
22+
23+
void setup() {
24+
// iterate over the notes of the melody:
25+
for (int thisNote = 0; thisNote < 8; thisNote++) {
26+
27+
// to calculate the note duration, take one second divided by the note type.
28+
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
29+
int noteDuration = 1000 / noteDurations[thisNote];
30+
carrier.Buzzer.sound(melody[thisNote]);
31+
delay(noteDuration);
32+
// to distinguish the notes, set a minimum time between them.
33+
// the note's duration + 30% seems to work well:
34+
int pauseBetweenNotes = noteDuration * 1.30;
35+
delay(pauseBetweenNotes);
36+
// stop the tone playing:
37+
carrier.Buzzer.noSound();
38+
}
39+
}
40+
41+
void loop() {
42+
// no need to repeat the melody.
43+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*************************************************
2+
* Public Constants
3+
*************************************************/
4+
5+
#define NOTE_B0 31
6+
#define NOTE_C1 33
7+
#define NOTE_CS1 35
8+
#define NOTE_D1 37
9+
#define NOTE_DS1 39
10+
#define NOTE_E1 41
11+
#define NOTE_F1 44
12+
#define NOTE_FS1 46
13+
#define NOTE_G1 49
14+
#define NOTE_GS1 52
15+
#define NOTE_A1 55
16+
#define NOTE_AS1 58
17+
#define NOTE_B1 62
18+
#define NOTE_C2 65
19+
#define NOTE_CS2 69
20+
#define NOTE_D2 73
21+
#define NOTE_DS2 78
22+
#define NOTE_E2 82
23+
#define NOTE_F2 87
24+
#define NOTE_FS2 93
25+
#define NOTE_G2 98
26+
#define NOTE_GS2 104
27+
#define NOTE_A2 110
28+
#define NOTE_AS2 117
29+
#define NOTE_B2 123
30+
#define NOTE_C3 131
31+
#define NOTE_CS3 139
32+
#define NOTE_D3 147
33+
#define NOTE_DS3 156
34+
#define NOTE_E3 165
35+
#define NOTE_F3 175
36+
#define NOTE_FS3 185
37+
#define NOTE_G3 196
38+
#define NOTE_GS3 208
39+
#define NOTE_A3 220
40+
#define NOTE_AS3 233
41+
#define NOTE_B3 247
42+
#define NOTE_C4 262
43+
#define NOTE_CS4 277
44+
#define NOTE_D4 294
45+
#define NOTE_DS4 311
46+
#define NOTE_E4 330
47+
#define NOTE_F4 349
48+
#define NOTE_FS4 370
49+
#define NOTE_G4 392
50+
#define NOTE_GS4 415
51+
#define NOTE_A4 440
52+
#define NOTE_AS4 466
53+
#define NOTE_B4 494
54+
#define NOTE_C5 523
55+
#define NOTE_CS5 554
56+
#define NOTE_D5 587
57+
#define NOTE_DS5 622
58+
#define NOTE_E5 659
59+
#define NOTE_F5 698
60+
#define NOTE_FS5 740
61+
#define NOTE_G5 784
62+
#define NOTE_GS5 831
63+
#define NOTE_A5 880
64+
#define NOTE_AS5 932
65+
#define NOTE_B5 988
66+
#define NOTE_C6 1047
67+
#define NOTE_CS6 1109
68+
#define NOTE_D6 1175
69+
#define NOTE_DS6 1245
70+
#define NOTE_E6 1319
71+
#define NOTE_F6 1397
72+
#define NOTE_FS6 1480
73+
#define NOTE_G6 1568
74+
#define NOTE_GS6 1661
75+
#define NOTE_A6 1760
76+
#define NOTE_AS6 1865
77+
#define NOTE_B6 1976
78+
#define NOTE_C7 2093
79+
#define NOTE_CS7 2217
80+
#define NOTE_D7 2349
81+
#define NOTE_DS7 2489
82+
#define NOTE_E7 2637
83+
#define NOTE_F7 2794
84+
#define NOTE_FS7 2960
85+
#define NOTE_G7 3136
86+
#define NOTE_GS7 3322
87+
#define NOTE_A7 3520
88+
#define NOTE_AS7 3729
89+
#define NOTE_B7 3951
90+
#define NOTE_C8 4186
91+
#define NOTE_CS8 4435
92+
#define NOTE_D8 4699
93+
#define NOTE_DS8 4978
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include <Arduino_MKRIoTCarrier.h>
2+
3+
MKRIoTCarrier carrier;
4+
bool CARRIER_CASE = false;
5+
6+
void setup() {
7+
8+
Serial.begin(9600);
9+
Serial.println("Init");
10+
carrier.begin();
11+
}
12+
13+
void loop() {
14+
//Switch to NO
15+
carrier.Relay1.open();
16+
carrier.Relay2.open();
17+
Serial.println("Both Relays switched to NO");
18+
delay(2500);
19+
20+
21+
//Switch to NC
22+
carrier.Relay1.close();
23+
carrier.Relay2.close();
24+
Serial.println("Both Relays switched to NC");
25+
26+
//Get status
27+
Serial.print("Relay 1 is: ");
28+
Serial.println(carrier.Relay1.getStatus());
29+
delay(2500);
30+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/* This sketch will test everything on the carrier board
2+
3+
This library "Arduino_IOTSKcarrier.h" wraps the 4 sensor's libraries to make it more compact
4+
It has also the Relays to make it easier to use them
5+
6+
The TFT display library is accesed by "display" instead of "tft"
7+
8+
Below you will see how to access everything inside the Carrier, not every functionalities
9+
*/
10+
11+
#include <Arduino_MKRIoTCarrier.h>
12+
MKRIoTCarrier carrier; //Constructor of the carrier maybe we can include it on the library itself
13+
14+
//Set the pad sense distance for using them with or without the enclosure
15+
bool CARRIER_CASE = false;
16+
17+
float temperature;
18+
float humidity;
19+
20+
int light;
21+
int r,g,b;
22+
23+
float pressure;
24+
25+
float Gx, Gy, Gz;
26+
float Ax, Ay, Az;
27+
28+
void setup() {
29+
// put your setup code here, to run once:
30+
//Start Serial comm
31+
Serial.begin(9600);
32+
while (!Serial); //Wait to open the Serial monitor to start the program and see details on errors
33+
34+
//SD card
35+
//You can init the SD card with SD.begin(SD_CS)
36+
//SD_CS refers to pin 0
37+
38+
//Init everything and outputs the errors
39+
carrier.begin();
40+
41+
42+
}
43+
44+
void loop() {
45+
// put your main code here, to run repeatedly:
46+
//LED show up
47+
//( led index , red , green , blue )
48+
carrier.leds.setPixelColor(0, 0 , 0 , 20);
49+
carrier.leds.show();
50+
//Function to display
51+
displayTitle();
52+
53+
//Buzzer sound sound(freq)
54+
/*
55+
* Can be used also with tone(BUZZER , freq);
56+
*/
57+
carrier.Buzzer.sound(8000);
58+
delay(100);
59+
carrier.Buzzer.noSound();
60+
61+
//Simple relay open and close loop
62+
/* Relay function
63+
open() - goes to Normally Open (NO) circuit, status LED will be OFF
64+
close() - goes to Normally Close (NC) cirucit, status LED will be ON
65+
*/
66+
carrier.Relay1.close();
67+
delay(1000);
68+
printStatus();
69+
delay(100);
70+
71+
carrier.Relay1.open();
72+
delay(1000);
73+
printStatus();
74+
delay(100);
75+
76+
printStatus();
77+
carrier.Relay2.close();
78+
delay(1000);
79+
printStatus();
80+
delay(100);
81+
82+
carrier.Relay2.open();
83+
delay(1000);
84+
printStatus();
85+
delay(100);
86+
87+
delay(1000);
88+
89+
90+
//SENSORS
91+
//Ambient light sensor
92+
//It set the values that you point inside the brackets
93+
while (! carrier.Light.colorAvailable()) {
94+
delay(5);
95+
}
96+
carrier.Light.readColor(r,g, b, light);
97+
Serial.println("Ambient light sensor");
98+
Serial.print("\t light: ");
99+
Serial.println(light);
100+
displayLight();
101+
102+
//Env sensor
103+
temperature = carrier.Env.readTemperature();
104+
humidity = carrier.Env.readHumidity();
105+
Serial.println("Env sensor");
106+
Serial.print("\t Temperature:");
107+
Serial.println(temperature);
108+
Serial.print("\t Humidity: ");
109+
Serial.println(humidity);
110+
displayEnv();
111+
112+
//Barometric sensor
113+
pressure = carrier.Pressure.readPressure();
114+
Serial.println("Barometric sensor");
115+
Serial.print("\t Pressure:");
116+
Serial.println(pressure);
117+
displayBaro();
118+
119+
//IMU
120+
//Gyroscope
121+
Serial.println("IMU module");
122+
carrier.IMUmodule.readGyroscope(Gx, Gy, Gz);
123+
Serial.println("Gyroscope:");
124+
Serial.print ("\t X:");
125+
Serial.println(Gx);
126+
Serial.print ("\t Y:");
127+
Serial.println(Gy);
128+
Serial.print ("\t Z:");
129+
Serial.println(Gz);
130+
131+
//Accelerometer
132+
carrier.IMUmodule.readAcceleration(Ax, Ay, Az);
133+
Serial.println("Accelerometer:");
134+
Serial.print ("\t X:");
135+
Serial.println(Ax);
136+
Serial.print ("\t Y:");
137+
Serial.println(Ay);
138+
Serial.print ("\t Z:");
139+
Serial.println(Az);
140+
141+
Serial.println();
142+
Serial.println("--- \t END OF READS \t ---");
143+
Serial.println();
144+
145+
146+
147+
}
148+
149+
void displayTitle() {
150+
carrier.display.fillScreen(ST77XX_BLACK);
151+
152+
carrier.display.setCursor(80, 120);
153+
carrier.display.setTextColor(ST77XX_RED);
154+
carrier.display.print("IoT ");
155+
carrier.display.setTextColor(ST77XX_GREEN);
156+
carrier.display.print("Starter ");
157+
carrier.display.setTextColor(ST77XX_MAGENTA);
158+
carrier.display.print("Kit");
159+
carrier.display.setCursor(105, 130);
160+
carrier.display.setTextColor(ST77XX_WHITE);
161+
carrier.display.print("Library");
162+
}
163+
164+
void printStatus() {
165+
carrier.display.fillScreen(ST77XX_BLACK); //oled clear()
166+
carrier.display.setCursor(70, 100);
167+
carrier.display.setTextColor(ST77XX_BLUE);
168+
carrier.display.print("Relay 1 status: ");
169+
carrier.display.setTextColor(ST77XX_RED);
170+
carrier.display.print(carrier.Relay1.getStatus());
171+
172+
carrier.display.setCursor(70, 120);
173+
carrier.display.setTextColor(ST77XX_BLUE);
174+
carrier.display.print("Relay 2 status: ");
175+
carrier.display.setTextColor(ST77XX_RED);
176+
carrier.display.print(carrier.Relay2.getStatus());
177+
178+
}
179+
180+
void displayLight() {
181+
carrier.display.fillScreen(ST77XX_BLACK); //oled clear()
182+
carrier.display.setCursor(70, 100);
183+
carrier.display.print("Light: ");
184+
carrier.display.setTextColor(ST77XX_MAGENTA);
185+
carrier.display.print(light);
186+
delay(2500);
187+
}
188+
189+
void displayEnv() {
190+
carrier.display.fillScreen(ST77XX_BLACK); //oled clear()
191+
carrier.display.setCursor(70, 100);
192+
carrier.display.print("Humidity: ");
193+
carrier.display.setTextColor(ST77XX_MAGENTA);
194+
carrier.display.print(humidity);
195+
carrier.display.setCursor(70, 115);
196+
carrier.display.print("Temperature: ");
197+
carrier.display.setTextColor(ST77XX_BLUE);
198+
carrier.display.print(temperature);
199+
delay(2500);
200+
}
201+
202+
void displayBaro() {
203+
}

0 commit comments

Comments
 (0)