Created
December 15, 2015 23:34
-
-
Save polygondoor/410a28d7ec4cea32c774 to your computer and use it in GitHub Desktop.
screenPlay 6
This file contains 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 <Adafruit_SSD1306.h> | |
#define OLED_RESET 4 | |
Adafruit_SSD1306 display(OLED_RESET); | |
void setup() { | |
// tell the little OLED screen that we are 128 x 32 pixels | |
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // dont worry about this line, it looks complex | |
// set text size and other things | |
display.setTextSize(1); | |
display.setTextColor(WHITE); | |
display.setTextWrap(1); | |
// Tell the Arduino that pin 3 is an input pin. | |
pinMode(3, INPUT); | |
} | |
int x = 0; | |
int buttonState = 0; | |
int lightSensor = 0; | |
void loop() { | |
lightSensor = analogRead(0) / 10; | |
// see if button has been pressed | |
buttonState = digitalRead(3); | |
if (buttonState == HIGH) { x = 0; } | |
// increment x | |
x = x + 1; | |
// draw my icon | |
display.clearDisplay(); | |
drawIcon(x, 16); | |
// write the resistor value | |
display.setCursor(0, 20); | |
display.print( lightSensor ); | |
// send info to display | |
display.display(); | |
} | |
void drawIcon(int x, int y) | |
{ | |
// display.setCursor(16, 16); | |
display.drawCircle(x + 16, y, lightSensor / 2, WHITE); | |
display.fillCircle(x + 10, y - 4, 4, WHITE); | |
display.fillCircle(x + 22, y - 4, 4, WHITE); | |
display.fillCircle(x + 11, y - 4, 2, BLACK); | |
display.fillCircle(x + 23, y - 4, 2, BLACK); | |
display.drawLine(x+10, y+6, x+22, y+6, WHITE); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment