Instantly share code, notes, and snippets.

Embed
What would you like to do?
1984 Telescreen Using Arduino IDE
~Created by Chloe Quinto~
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
int note [] = {2349,1976,1397};
int REDled = 5;
int calibrationTime = 30;
long unsigned int lowIn;
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 3;
int OLEDPin = 13;
void setup() {
Serial.begin(9600);
for(int index = 0; index < 3; index++)
{
tone(4, note[index], 500);
delay(750);
}
pinMode(pirPin, INPUT);
pinMode(REDled, OUTPUT);
digitalWrite(pirPin, LOW);
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++)
{
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
pinMode(OLEDPin, OUTPUT);
}
void loop(){
if(digitalRead(pirPin) == HIGH){
digitalWrite(OLEDPin, HIGH);
if(lockLow){
lockLow = false;
Serial.println("---");
Serial.print("motion detected at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
display.begin(SSD1306_SWITCHCAPVCC);
display.clearDisplay();
testscrolltext();
display.clearDisplay();
digitalWrite(REDled, LOW);
delay(7000);
digitalWrite(REDled, HIGH); //dot
delay(1000);
digitalWrite(REDled, LOW);
delay(1000);
digitalWrite(REDled, HIGH); //dot
delay(1000);
digitalWrite(REDled, LOW);
delay(1000);
digitalWrite(REDled, HIGH); //dot
delay(1000);
digitalWrite(REDled, LOW); //pause 7 seconds
delay(7000);
digitalWrite(REDled, HIGH); //dash
delay(3000);
digitalWrite(REDled, LOW);
delay(1000);
digitalWrite(REDled, HIGH); //dash
delay(3000);
digitalWrite(REDled, LOW);
delay(1000);
digitalWrite(REDled, HIGH); //dash
delay(3000);
digitalWrite(REDled, LOW); // pause 7 seconds
delay(7000);
digitalWrite(REDled, HIGH); //dot
delay(1000);
digitalWrite(REDled, LOW); //dot
delay(1000);
digitalWrite(REDled, HIGH); //dot
delay(1000);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
digitalWrite(OLEDPin, LOW);
if(takeLowTime){
lowIn = millis();
takeLowTime = false;
}
if(!lockLow && millis() - lowIn > pause){
lockLow = true;
display.clearDisplay();
Serial.print("motion ended at ");
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}
void testscrolltext(void) {
display.setTextSize(1.25);
display.setTextColor(WHITE);
display.setCursor(40,5);
display.println("Big Brother");
display.setCursor(25,13);
display.println("is watching you");
display.display();
display.clearDisplay();
display.startscrollright(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrollleft(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrolldiagright(0x00, 0x07);
delay(2000);
display.startscrolldiagleft(0x00, 0x07);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrollleft(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(1000);
display.startscrollright(0x00, 0x0F);
delay(2000);
display.stopscroll();
delay(10000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment