Arduino TKJHAT
Arduino library for Pico HAT extension board
Loading...
Searching...
No Matches
Demo.ino
1// This demo shows how to use different components of the TKJHAT library together
2// This demo will read the light intensity from light sensor, and display it on the OLED screen
3// Button will be used to toggle between showing light intensity and showing a static message "STOPPED"
4
5#include "TKJHAT.h"
6
7TKJHAT hat;
8
9// hat.begin() initializes all the components on the HAT
10void setup() {
11 hat.begin();
12}
13
14void loop () {
15 // Read light intensity from the sensor
16 uint32_t lux = hat.lightSensor.readLight();
17 // Check if button1 is not pressed
18 if (!hat.button1.isPressed()) {
19 // If button1 is not pressed, show the light intensity on the display
20 hat.display.clear();
21 // Type: void Display::writeTextPositioned(int16_t x, int16_t y, const char* text, uint8_t scale){}
22 hat.display.writeTextPositioned(0, 0, "Light Intensity:", 1);
23 String text = String(lux);
24 hat.display.writeTextPositioned(0, 16, text.c_str(), 1);
25 } else {
26 // If button1 is pressed, show "STOPPED" on the display
27 hat.display.clear();
28 hat.display.writeTextPositioned(0, 0, "STOPPED");
29 }
30}
Main interface for accessing TKJHAT board features.
Definition TKJHAT.h:35
void begin()
Initialize all peripherals on the HAT Also initializes the default I2C bus for sensors and display.