Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************************************************
- This is an example for our Monochrome OLEDs based on SSD1306 drivers
- Pick one up today in the adafruit shop!
- ------> http://www.adafruit.com/category/63_98
- This example is for a 128x64 size display using I2C to communicate
- 3 pins are required to interface (2 I2C and one reset)
- Adafruit invests time and resources providing this open source code,
- please support Adafruit and open-source hardware by purchasing
- products from Adafruit!
- Written by Limor Fried/Ladyada for Adafruit Industries.
- BSD license, check license.txt for more information
- All text above, and the splash screen must be included in any redistribution
- *********************************************************************/
- #include <SPI.h>
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SSD1306.h>
- #define OLED_RESET 4
- Adafruit_SSD1306 display(OLED_RESET);
- #if (SSD1306_LCDHEIGHT != 64)
- #error("Height incorrect, please fix Adafruit_SSD1306.h!");
- #endif
- #define RELAY1 4
- #define RELAY2 5
- #define RELAY3 6
- #define RELAY4 7
- #define DELAY 1000
- void setup() {
- Serial.begin(9600);
- pinMode(RELAY1, OUTPUT);
- pinMode(RELAY2, OUTPUT);
- pinMode(RELAY3, OUTPUT);
- pinMode(RELAY4, OUTPUT);
- // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3D (for the 128x64)
- // init done
- display.clearDisplay();
- display.setTextSize(2);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.setCursor(30, 0);
- display.println("Relays");
- display.setCursor(0, 20);
- display.println("1 2 3 4");
- display.display();
- switchRelay(RELAY1, 0, false);
- switchRelay(RELAY2, 1, false);
- switchRelay(RELAY3, 2, false);
- switchRelay(RELAY4, 3, false);
- }
- void loop() {
- // 1 = OFF; 0 = ON
- // Relay 1 ON
- switchRelay(RELAY1, 0, true);
- delay(DELAY);
- // Relay 2 ON
- switchRelay(RELAY2, 1, true);
- delay(DELAY);
- // Relay 3 ON
- switchRelay(RELAY3, 2, true);
- delay(DELAY);
- // Relay 4 ON
- switchRelay(RELAY4, 3, true);
- delay(DELAY);
- // Relay 1 OFF
- switchRelay(RELAY1, 0, false);
- delay(DELAY);
- // Relay 2 OFF
- switchRelay(RELAY2, 1, false);
- delay(DELAY);
- // Relay 3 OFF
- switchRelay(RELAY3, 2, false);
- delay(DELAY);
- // Relay 4 OFF
- switchRelay(RELAY4, 3, false);
- delay(DELAY);
- }
- void switchRelay(int port, int order, bool state) {
- digitalWrite(port, state ? 0 : 1);
- display.fillRect(order*24, 35, 15, 15, (uint8_t)0);
- display.setTextSize(2);
- display.setCursor(order*24, 35);
- display.print(state ? "I " : "O ");
- display.display();
- }
Advertisement
Add Comment
Please, Sign In to add comment