OLED_featherwing.ino (2053B)
1 #include <SPI.h> 2 #include <Wire.h> 3 #include <Adafruit_GFX.h> 4 #include <Adafruit_SSD1306.h> 5 6 Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &Wire); 7 8 // OLED FeatherWing buttons map to different pins depending on board: 9 #if defined(ESP8266) 10 #define BUTTON_A 0 11 #define BUTTON_B 16 12 #define BUTTON_C 2 13 #elif defined(ESP32) 14 #define BUTTON_A 15 15 #define BUTTON_B 32 16 #define BUTTON_C 14 17 #elif defined(ARDUINO_STM32_FEATHER) 18 #define BUTTON_A PA15 19 #define BUTTON_B PC7 20 #define BUTTON_C PC5 21 #elif defined(TEENSYDUINO) 22 #define BUTTON_A 4 23 #define BUTTON_B 3 24 #define BUTTON_C 8 25 #elif defined(ARDUINO_FEATHER52832) 26 #define BUTTON_A 31 27 #define BUTTON_B 30 28 #define BUTTON_C 27 29 #else // 32u4, M0, M4, nrf52840 and 328p 30 #define BUTTON_A 9 31 #define BUTTON_B 6 32 #define BUTTON_C 5 33 #endif 34 35 void setup() { 36 Serial.begin(9600); 37 38 Serial.println("OLED FeatherWing test"); 39 // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally 40 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32 41 42 Serial.println("OLED begun"); 43 44 // Show image buffer on the display hardware. 45 // Since the buffer is intialized with an Adafruit splashscreen 46 // internally, this will display the splashscreen. 47 display.display(); 48 delay(1000); 49 50 // Clear the buffer. 51 display.clearDisplay(); 52 display.display(); 53 54 Serial.println("IO test"); 55 56 pinMode(BUTTON_A, INPUT_PULLUP); 57 pinMode(BUTTON_B, INPUT_PULLUP); 58 pinMode(BUTTON_C, INPUT_PULLUP); 59 60 // text display tests 61 display.setTextSize(1); 62 display.setTextColor(SSD1306_WHITE); 63 display.setCursor(0,0); 64 display.print("Connecting to SSID\n'adafruit':"); 65 display.print("connected!"); 66 display.println("IP: 10.0.1.23"); 67 display.println("Sending val #0"); 68 display.setCursor(0,0); 69 display.display(); // actually display all of the above 70 } 71 72 void loop() { 73 if(!digitalRead(BUTTON_A)) display.print("A"); 74 if(!digitalRead(BUTTON_B)) display.print("B"); 75 if(!digitalRead(BUTTON_C)) display.print("C"); 76 delay(10); 77 yield(); 78 display.display(); 79 }