Skip to content

Instantly share code, notes, and snippets.

@ngs
Created January 25, 2021 00:55
Show Gist options
  • Save ngs/131bbcebd8ee4f626afb497870e4d3a9 to your computer and use it in GitHub Desktop.
Save ngs/131bbcebd8ee4f626afb497870e4d3a9 to your computer and use it in GitHub Desktop.
#include <Arduino_MKRIoTCarrier.h>
MKRIoTCarrier carrier;
float temperature = 0;
float humidity = 0;
float pressure = 0;
float gyroscope_x, gyroscope_y, gyroscope_z;
float accelerometer_x, accelerometer_y, accelerometer_z;
float pixel = 3, r = 25, g = 20, b = 40;
int none = 0;
int light = 1;
void setup() {
while (!Serial);
CARRIER_CASE = true;
carrier.begin();
}
void loop() {
temperature = carrier.Env.readTemperature(); //reads temperature
humidity = carrier.Env.readHumidity(); //reads humidity
pressure = carrier.Pressure.readPressure(); //reads pressure
//reads IMU sensor
carrier.IMUmodule.readGyroscope(gyroscope_x, gyroscope_y, gyroscope_z); //read gyroscope (x, y z)
carrier.IMUmodule.readAcceleration(accelerometer_x, accelerometer_y, accelerometer_z); //read accelerometer (x, y z)
//reads ambient light
if (carrier.Light.colorAvailable()) {
carrier.Light.readColor(none, none, none, light);
}
//updates state of all buttons
carrier.Buttons.update();
//checks if button 1 has been pressed
if (carrier.Button1.onTouchDown()) {
//controlling screen
carrier.display.fillScreen(ST77XX_BLUE); //red background
carrier.display.setTextColor(ST77XX_WHITE); //white text
carrier.display.setTextSize(3); //medium sized text
carrier.display.setCursor(20, 110); //sets position for printing (x and y)
carrier.display.print("Touched!!"); //prints text
carrier.Buzzer.sound(500);
delay(1000);
carrier.Buzzer.noSound();
return;
}
carrier.leds.setPixelColor(pixel, g , r , b); //sets pixels. e.g. 3, 255, 0 , 255
carrier.leds.show(); //displays pixels
carrier.Relay1.open(); //opens relay 1
carrier.Relay1.close(); //closes relay 1
// carrier.Buzzer.sound(500); //sets frequency of buzzer
// delay(1000); //sets duration for sounds
// carrier.Buzzer.sound(100); //sets frequency of buzzer
// delay(1000); //sets duration for sounds
// carrier.Buzzer.noSound(); //stops buzzer
//controlling screen
carrier.display.fillScreen(ST77XX_BLACK); //red background
carrier.display.setTextColor(ST77XX_WHITE); //white text
carrier.display.setTextSize(2); //medium sized text
carrier.display.setCursor(20, 110); //sets position for printing (x and y)
carrier.display.print("Temp: "); //prints text
carrier.display.print(temperature); //prints a variable
carrier.display.println(" C"); //prints text
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment