Last active
May 1, 2016 21:05
-
-
Save easai/d94bcad0af4e58c84db4e8bd22b75495 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <IRremote.h> | |
int pinCLK = 10; | |
int pinCS = 9; | |
int pinDIN = 8; | |
boolean displayOn = false; | |
int pir = 2; | |
int remote = 3; | |
IRrecv irrecv(remote); | |
decode_results results; | |
unsigned char dat[8] = {0b010000001, | |
0b001011010, | |
0b000100100, | |
0b001011010, | |
0b001011010, | |
0b000100100, | |
0b001011010, | |
0b010000001 | |
}; | |
unsigned char heart[8] = {0b00000000, | |
0b01100110, | |
0b11111111, | |
0b11111111, | |
0b11111111, | |
0b01111110, | |
0b00111100, | |
0b00011000 | |
}; | |
unsigned char smily[8] = {0b00000000, | |
0b01000010, | |
0b11100111, | |
0b01000010, | |
0b00000000, | |
0b01000010, | |
0b00100100, | |
0b00011000 | |
}; | |
unsigned char handsup[8] = {0b10000001, | |
0b01011010, | |
0b00100100, | |
0b00011000, | |
0b00011000, | |
0b00011000, | |
0b00011000, | |
0b00100100 | |
}; | |
unsigned char handshoriz[8] = {0b00000000, | |
0b00011000, | |
0b11100111, | |
0b00011000, | |
0b00011000, | |
0b00011000, | |
0b00011000, | |
0b00100100 | |
}; | |
unsigned char handsdown[8] = {0b00000000, | |
0b00011000, | |
0b00100100, | |
0b01011010, | |
0b10011001, | |
0b00011000, | |
0b00011000, | |
0b00100100 | |
}; | |
void WriteByte(unsigned char DATA) | |
{ | |
unsigned char i; | |
digitalWrite(pinCS, LOW); | |
for (i = 8; i >= 1; i--) | |
{ | |
digitalWrite(pinCLK, LOW); | |
digitalWrite(pinDIN, DATA & 0x80); | |
DATA = DATA << 1; | |
digitalWrite(pinCLK, HIGH); | |
} | |
} | |
void writeChar(unsigned char address, unsigned char dat) | |
{ | |
digitalWrite(pinCS, LOW); | |
WriteByte(address); | |
WriteByte(dat); | |
digitalWrite(pinCS, HIGH); | |
} | |
void clearScreen() | |
{ | |
for (int i = 1; i < 9; i++) | |
writeChar(i, 0); | |
} | |
void initDisplay(void) | |
{ | |
writeChar(0x09, 0x00); | |
writeChar(0x0a, 0x03); | |
writeChar(0x0b, 0x07); | |
writeChar(0x0c, 0x01); | |
writeChar(0x0f, 0x00); | |
} | |
void setup() | |
{ | |
pinMode(pir, INPUT_PULLUP); | |
pinMode(remote, INPUT_PULLUP); | |
pinMode(pinCLK, OUTPUT); | |
pinMode(pinCS, OUTPUT); | |
pinMode(pinDIN, OUTPUT); | |
delay(50); | |
initDisplay(); | |
displayOn = true; | |
irrecv.enableIRIn(); | |
attachInterrupt(digitalPinToInterrupt(pir), displayToggle, CHANGE); | |
attachInterrupt(digitalPinToInterrupt(remote), checkRemote, CHANGE); | |
} | |
void checkRemote() | |
{ | |
if (irrecv.decode(&results)) { | |
displayOn = !displayOn; | |
irrecv.resume(); | |
} | |
} | |
void displayToggle() | |
{ | |
displayOn = !displayOn; | |
} | |
void loop() | |
{ | |
if (displayOn) | |
{ | |
for (int j = 0; j < 5; j++) | |
{ | |
for (int i = 1; i < 9; i++) | |
writeChar(i, handsup[i - 1]); | |
delay(100); | |
for (int i = 1; i < 9; i++) | |
writeChar(i, handshoriz[i - 1]); | |
delay(100); | |
for (int i = 1; i < 9; i++) | |
writeChar(i, handsdown[i - 1]); | |
delay(100); | |
for (int i = 1; i < 9; i++) | |
writeChar(i, handshoriz[i - 1]); | |
delay(100); | |
} | |
for (int i = 1; i < 9; i++) | |
writeChar(i, smily[i - 1]); | |
delay(1000); | |
for (int i = 1; i < 9; i++) | |
writeChar(i, heart[i - 1]); | |
delay(1000); | |
displayOn = false; | |
clearScreen(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment