Archive of Arduino Projects
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

430 lines
11 KiB

#include "/Users/Imogen/Documents/Arduino/libraries/IRremote/IRremote.h"
#include "/Users/Imogen/Documents/Arduino/libraries/IRremote/IRremote.cpp"
// PIN FOR RECEIVER
int receiver = 3; // Signal Pin of IR receiver to Arduino Digital Pin 11
/*-----( Declare objects )-----*/
IRrecv irrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
/*-----( Function )-----*/
void translateIR() // takes action based on IR code received
// describing Remote IR codes
{
switch (results.value)
{
case 0xFFA25D: Serial.println("POWER"); off(); break;
case 0xFFE21D: Serial.println("FUNC/STOP"); break;
case 0xFF629D: Serial.println("VOL+"); break;
case 0xFF22DD: Serial.println("FAST BACK"); break;
case 0xFF02FD: Serial.println("PAUSE"); break;
case 0xFFC23D: Serial.println("FAST FORWARD"); break;
case 0xFFE01F: Serial.println("DOWN"); break;
case 0xFFA857: Serial.println("VOL-"); break;
case 0xFF906F: Serial.println("UP"); break;
case 0xFF9867: Serial.println("EQ"); downup(6, 9, 0); off(); break;
case 0xFFB04F: Serial.println("ST/REPT"); downup(0, 9, 0); off(); break;
case 0xFF6897: Serial.println("0"); all(0); break;
case 0xFF30CF: Serial.println("1"); all(1); break;
case 0xFF18E7: Serial.println("2"); all(2); break;
case 0xFF7A85: Serial.println("3"); all(3); break;
case 0xFF10EF: Serial.println("4"); all(4); break;
case 0xFF38C7: Serial.println("5"); all(5); break;
case 0xFF5AA5: Serial.println("6"); all(6); break;
case 0xFF42BD: Serial.println("7"); all(7); break;
case 0xFF4AB5: Serial.println("8"); all(8); break;
case 0xFF52AD: Serial.println("9"); all(9); break;
case 0xFFFFFFFF: Serial.println(" REPEAT"); break;
default:
Serial.println(" other button ");
}// End Case
delay(1000); // Do not get immediate repeat
} //END translateIR
///////////////////////////////////////////////
//display pins
int segA = 5; // >> 11
int segB = 13; // >> 7
int segC = 10; // >> 4
int segD = 8; // >> 2
int segE = 7; // >> 1
int segF = 4; // >> 10
int segG = 11; // >> 5
int segPt = 9; // >> 3
//------------//
//display digit
int d1 = 6; // >> 12
int d2 = 3; // >> 9
int d3 = 2; // >> 8
int d4 = 12; // >> 6
//------------//
int delayTime = 5000; //delayTime <Don't change it, if you don't know where is it!>
int mydelay = 3000; // 50 is about one second, 3000 a minute
int i = 0;
//=============================================//
//init all pin used
void setup() {
Serial.begin(9600);
Serial.println("IR Receiver Button Decode - Initializing...");
irrecv.enableIRIn(); // Start the receiver
pinMode(2, OUTPUT);
// pinMode(3, OUTPUT); // reserved for IR input
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
//=======================================================================================//
//void loop() {
//downup(0,20,9,0); // numbers above 19 display as blank.
////all(8);
////writeN(1,9,0,4);
//}
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
// Serial.println(results.value); // for debugging
translateIR();
irrecv.resume(); // receive the next value
}
}/* --(end main loop )-- */
//=======================================================================================//
//Write a Number - writeN(1,9,9,0) -> 1990
void writeN(int a, int b, int c, int d) {
selectDwriteL(1, a);
selectDwriteL(2, b);
selectDwriteL(3, c);
selectDwriteL(4, d);
}
//=============================================//
//Make a Number Number Countdown (Timers).
void downup(int A, int C, int D) {
irrecv.resume();
int a=0;
int c, d;
bool FLAG = 0;
while (a <= A) {
c = C;
d = D;
while (c != -1) {
while (d != -1) {
while (i < mydelay) { // i here is like a timer ! because we can't use delay function
selectDwriteL(1, a);
selectDwriteL(3, c);
selectDwriteL(4, d);
if (irrecv.decode(&results)) // have we received an IR signal?
{
// if(results.value == 16753245){
translateIR();
FLAG = 1;
// break;
irrecv.resume(); // receive the next value
// }
}
i++;
if(FLAG){d=0;a=A;c=0;i=mydelay;}
}
i = 0;
d--;
}
d = 9;
c--;
}
// c = 9; // third digit
a++; // iterate the first digit to count up while the last two digits count down.
//b--; // this uncommented leaves the second digit blank
}
}
//=============================================//
//Make a Number Number Countdown (Timers).
void down(int a, int b, int c, int d) {
while (a != -1) {
while (b != -1) {
while (c != -1) {
while (d != -1) {
while (i < mydelay) { // i here is like a timer ! because we can't use delay function
selectDwriteL(1, a);
selectDwriteL(2, b);
selectDwriteL(3, c);
selectDwriteL(4, d);
i++;
}
i = 0;
d--;
}
d = 9;
c--;
}
c = 9;
b--;
}
b = 9;
a--;
}
}
//=============================================//
//Select Which Digit (selectD) is going to Display (writeL)
void selectDwriteL(int d, int l) {
switch (d) { // choose a digit
case 0: digitalWrite(d1, LOW); //case 0 - All ON
digitalWrite(d2, LOW);
digitalWrite(d3, LOW);
digitalWrite(d4, LOW);
break;
case 1: digitalWrite(d1, LOW);//case 1 - Digit Number 1
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
case 2: digitalWrite(d1, HIGH);//case 1 - Digit Number 2
digitalWrite(d2, LOW);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
case 3: digitalWrite(d1, HIGH);//case 1 - Digit Number 3
digitalWrite(d2, HIGH);
digitalWrite(d3, LOW);
digitalWrite(d4, HIGH);
break;
case 4: digitalWrite(d1, HIGH);//case 1 - Digit Number 4
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, LOW);
break;
case 5: digitalWrite(d1, HIGH); //case 0 - All ON
digitalWrite(d2, HIGH);
digitalWrite(d3, HIGH);
digitalWrite(d4, HIGH);
break;
}
switch (l) { // choose a Number
case 0: zero();
break;
case 1: one();
break;
case 2: two();
break;
case 3: three();
break;
case 4: four();
break;
case 5: five();
break;
case 6: six();
break;
case 7: seven();
break;
case 8: eight();
break;
case 9: nine();
break;
case 10: point(); // print a Point
break;
case 11: one(); digitalWrite(segPt, HIGH);
break;
case 12: two(); digitalWrite(segPt, HIGH);
break;
case 13: three(); digitalWrite(segPt, HIGH);
break;
case 14: four(); digitalWrite(segPt, HIGH);
break;
case 15: five(); digitalWrite(segPt, HIGH);
break;
case 16: six(); digitalWrite(segPt, HIGH);
break;
case 17: seven(); digitalWrite(segPt, HIGH);
break;
case 18: eight(); digitalWrite(segPt, HIGH);
break;
case 19: nine(); digitalWrite(segPt, HIGH);
break;
case -1: none();
break;
default: none(); // make all them off !
break;
}
delayMicroseconds(delayTime); // delayTime for nice display of the Number !
}
//=============================================//
//shown one Number in the 4 Digit
void all(int n) {
selectDwriteL(0, n);
}
void off() {
selectDwriteL(5, 0);
}
//=============================================//
void zero() {
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, LOW);
digitalWrite(segPt, LOW);
}
//=============================================//
void one() {
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segPt, LOW);
}
//=============================================//
void two() {
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, LOW);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void three() {
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void four() {
digitalWrite(segA, LOW);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void five() {
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void six() {
digitalWrite(segA, HIGH);
digitalWrite(segB, LOW);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void seven() {
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segPt, LOW);
}
//=============================================//
void eight() {
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, HIGH);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void nine() {
digitalWrite(segA, HIGH);
digitalWrite(segB, HIGH);
digitalWrite(segC, HIGH);
digitalWrite(segD, HIGH);
digitalWrite(segE, LOW);
digitalWrite(segF, HIGH);
digitalWrite(segG, HIGH);
digitalWrite(segPt, LOW);
}
//=============================================//
void point() {
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segPt, HIGH);
}
//=============================================//
void none() {
digitalWrite(segA, LOW);
digitalWrite(segB, LOW);
digitalWrite(segC, LOW);
digitalWrite(segD, LOW);
digitalWrite(segE, LOW);
digitalWrite(segF, LOW);
digitalWrite(segG, LOW);
digitalWrite(segPt, LOW);
}