#include <Wire.h>
#include <U8g2lib.h>
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0);
// RGB LED pins
#define RED 0
#define GREEN 1
#define BLUE 2
#define BUTTON1 16
#define BUTTON2 17
const char* line1 = "";
const char* line2 = "";
const char* line3 = "";
void setup() {
// put your setup code here, to run once:
Serial1.begin(115200);
Serial1.println("Hello, Raspberry Pi Pico!");
// Aktivera Pins flr RGB LED
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
// Aktivera knappar
pinMode(BUTTON1, INPUT_PULLUP);
pinMode(BUTTON2, INPUT_PULLUP);
21
Wire.begin();
u8g2.begin();
line1 = "Hej Raspberry!";
line2 = "OLED funkar!";
updateDisplay();
}
void loop() {
// put your main code here, to run repeatedly:
delay(1); // this speeds up the simulation
int R = 0;
int G = 0;
int B = 255;
if (digitalRead(BUTTON1) == LOW) {
R = 255;
B = 0;
line3 = "Knapp 1 tryckt";
}
if (digitalRead(BUTTON2) == LOW) {
G = 255;
B = 0;
line3 = "Knapp 2 tryckt";
}
if ((digitalRead(BUTTON1) == LOW) && (digitalRead(BUTTON2) == LOW)) {
line3 = "";
}
setColor(R, G, B);
updateDisplay();
}
// Funktion för att tända färger
void setColor(int R, int G, int B) {
analogWrite(RED, R);
analogWrite(GREEN, G);
analogWrite(BLUE, B);
}
void updateDisplay() {
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr);
u8g2.drawStr(0,10,line1);
u8g2.drawStr(0,20,line2);
u8g2.drawStr(0,30,line3);
u8g2.sendBuffer();
}Loading
ssd1306
ssd1306