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