Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #define CH1 3
- #define CH2 5
- #define CH3 6
- #define CH4 9
- #define CH5 10
- #define CH6 11
- #define SCREEN_WIDTH 128
- #define SCREEN_HEIGHT 64
- #define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin)
- #define SCREEN_ADDRESS 0x3C
- Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- // Integers to represent values from sticks and pots
- int ch1Value;
- int ch2Value;
- int ch3Value;
- int ch4Value;
- int ch5Value;
- // Boolean to represent switch value
- bool ch6Value;
- int readChannel(int channelInput, int minLimit, int maxLimit, int defaultValue) {
- int ch = pulseIn(channelInput, HIGH, 30000);
- if (ch < 100) return defaultValue;
- return map(ch, 1000, 2000, minLimit, maxLimit);
- }
- bool readSwitch(byte channelInput, bool defaultValue) {
- int intDefaultValue = (defaultValue) ? 100 : 0;
- int ch = readChannel(channelInput, 0, 100, intDefaultValue);
- return (ch > 50);
- }
- void setup() {
- Serial.begin(9600);
- pinMode(A0, INPUT);
- // Initialize SSD1306 display
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
- display.clearDisplay();
- display.setTextColor(SSD1306_WHITE);
- }
- void loop() {
- ch1Value = readChannel(CH1, -100, 100, 0);
- ch2Value = readChannel(CH2, -100, 100, 0);
- ch3Value = readChannel(CH3, -100, 100, -100);
- ch4Value = readChannel(CH4, -100, 100, 0);
- ch5Value = readChannel(CH5, -100, 100, 0);
- ch6Value = readSwitch(CH6, false);
- display.clearDisplay();
- // Przykład: Wyświetlanie wartości w kształcie słupków
- // Przekształć ch1Value i ch2Value do zakresu od 0 do 100
- int ch1BarLength = map(ch1Value, -100, 100, 0, 100);
- int ch2BarLength = map(ch2Value, -100, 100, 0, 100);
- int ch3BarLength = map(ch3Value, -100, 100, 0, 100);
- int ch4BarLength = map(ch4Value, -100, 100, 0, 100);
- int ch5BarLength = map(ch5Value, -100, 100, 0, 100);
- // Wyświetl paski
- display.drawRect(0, 0, ch1BarLength, 4, SSD1306_WHITE);
- display.drawRect(0, 10, ch2BarLength, 4, SSD1306_WHITE);
- display.drawRect(0, 20, ch3BarLength, 4, SSD1306_WHITE);
- display.drawRect(0, 30, ch4BarLength, 4, SSD1306_WHITE);
- display.drawRect(0, 40, ch5BarLength, 4, SSD1306_WHITE);
- // Przykład: Dodawanie tekstu
- display.setCursor(0, 50);
- display.setTextSize(1);
- display.setTextColor(SSD1306_WHITE);
- display.println("Switch: " + String(ch6Value));
- display.display();
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement