Created
March 20, 2026 11:10
-
-
Save kareiva/34d5cf9fe0b235fd13751da3b06de173 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <SPI.h> | |
| #include <Wire.h> | |
| #include <Adafruit_GFX.h> | |
| #include <Adafruit_SSD1306.h> | |
| #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) | |
| #define SCREEN_WIDTH 128 // OLED display width, in pixels | |
| #define SCREEN_HEIGHT 32 // OLED display height, in pixels | |
| #define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 | |
| #define LED_RED 13 | |
| #define LED_BLUE 12 | |
| #define LED_WHITE 14 | |
| #define LED_GREEN 15 | |
| #define LED_YELLOW 16 | |
| Adafruit_SSD1306 OLED(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); | |
| void setup() { | |
| Serial.begin(115200); | |
| Serial.println("Welcome"); | |
| // Wait for display | |
| delay(500); | |
| OLED.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS); | |
| OLED.clearDisplay(); | |
| OLED.setTextWrap(false); | |
| OLED.setTextSize(1); | |
| OLED.setTextColor(WHITE); | |
| OLED.setCursor(0,0); | |
| OLED.println("Labas pasauli"); | |
| OLED.display(); | |
| pinMode(LED_RED, OUTPUT); | |
| pinMode(LED_BLUE, OUTPUT); | |
| pinMode(LED_WHITE, OUTPUT); | |
| pinMode(LED_GREEN, OUTPUT); | |
| pinMode(LED_YELLOW, OUTPUT); | |
| } | |
| void loop() { | |
| float voltage; | |
| voltage = analogRead(A0); | |
| Serial.print("Voltage: "); | |
| Serial.print(voltage, 3); | |
| Serial.println(" V"); | |
| OLED.clearDisplay(); | |
| OLED.setCursor(0,0); | |
| OLED.setTextSize(1); | |
| OLED.print("Labas, suk rata: "); | |
| OLED.println((int) voltage); | |
| int big_number = (int) ( voltage / 15) % 32; | |
| OLED.setTextSize(3); | |
| OLED.print(" "); | |
| OLED.println(big_number); | |
| OLED.display(); | |
| // LEDS are here | |
| digitalWrite(LED_WHITE, bitRead(big_number,4)); | |
| digitalWrite(LED_BLUE, bitRead(big_number,3)); | |
| digitalWrite(LED_RED, bitRead(big_number,2)); | |
| digitalWrite(LED_GREEN, bitRead(big_number,1)); | |
| digitalWrite(LED_YELLOW, bitRead(big_number,0) ); | |
| delay(500); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment