Sector Lighthouse – version 1

 

Required Hardware:

1 x Arduino Nano
1 x Green LED 5mm
1 x  Red LED 5mm
1 x White LED 5mm
1 x IR Remote control module
20 cm wire

Printed parts:

1 x Base part
1 x Roof

Circuit / Wiring

Code:

 

// Include IR Remote Library by Ken Shirriff
#include 

// Define sensor pin
const int RECV_PIN = 4;
const int ledPin1 =  A0;
const int ledPin2 =  A1;

long previousMillis = 0;
long previousMillis2 = 0;

int ledState = LOW; 

// Define IR Receiver and Results Objects
IRrecv irrecv(RECV_PIN);
decode_results results;

 int verdi2 = 0;
 int verdi1 = 0;
void setup(){
  // Serial Monitor @ 9600 baud
  Serial.begin(9600);
  // Enable the IR Receiver
  irrecv.enableIRIn();
  pinMode (ledPin1, OUTPUT);
  pinMode (ledPin2, OUTPUT);
}
 
void loop(){

unsigned long currentMillis = millis();
  
  if (irrecv.decode(&results)){
    // Print Code in HEX
    //    Serial.println(results.value, HEX);

   switch(results.value)
   {
    case 0xFFA25D:

     Serial.println("Quick Serien");
     verdi1 = 1;
     break;
     case 0xFF629D:
     Serial.println("ISO");
     verdi1 = 2;
     break;
     case 0xFFE21D:
     Serial.println("FM");
     verdi1 = 3;
     break;
      case 0xFF22DD:
     Serial.println("Flash");
     verdi1 = 4;
     break;
      case 0xFF02FD:
     Serial.println("Kardinal");
     verdi1 = 5;
     break;
      case 0xFFC23D:
     Serial.println("Morse");
     verdi1 = 6;
     break;
      case 0xFFE01F:
     Serial.println("7");
     verdi1 = 8;
     break;
      case 0xFFA857:
     Serial.println("8");
     verdi1 = 8;
     break;
      case 0xFF906F:
     Serial.println("9");
     verdi1 = 8;
     break;
      case 0xFF9867:
     Serial.println("AV");
     verdi1 = 7;
     break;
      case 0xFF6897:
     Serial.println("*");
       Serial.println("Fast");
       verdi1 = 8;
     break;
      case 0xFFB04F:
     Serial.println("#");
     verdi1 = random(1,6);
     verdi2 = random(0,4);
     Serial.println(verdi1);
     break;
      case 0xFF18E7:
     Serial.println("o");
     if (verdi1 = 2) {
     verdi1 = verdi1 - 1;
     Serial.println(verdi1);
     }
     else {
      verdi1 = 6;
      Serial.println(verdi1);
      }
     break;
      case 0xFF10EF:
     Serial.println("V");
     if (verdi2 >= 2) {
     verdi2 = verdi2 - 1;
     Serial.println(verdi2);
     }
     else {
      verdi2 = 9;
      Serial.println(verdi2);
      }
     break;
      case 0xFF5AA5:
     Serial.println("H");
     if (verdi2  500 && currentMillis - previousMillis  1000) previousMillis = currentMillis;   
   break; 

case 1: // VQ
blinkOff(); 
if(currentMillis - previousMillis > 250 && currentMillis - previousMillis  500) previousMillis = currentMillis;  
break;

case 2: // UQ
blinkOff(); 
if(currentMillis - previousMillis > 125 && currentMillis - previousMillis  250) previousMillis = currentMillis; 
break;    

case 3:
verdi2 = 0;
break;
case 4:
verdi2 = 0;
break;
case 5:
verdi2 = 0;
break;
case 6:
verdi2 = 0;
break;
case 7:
verdi2 = 0;
break;
case 8:
verdi2 = 0;
break;
case 9:
verdi2 = 2;
break;
}
break;

case 2: //ISO
switch(verdi2) {

  case 0: //ISO1
  blinkOff(); 
if(currentMillis - previousMillis > 500 && currentMillis - previousMillis  1000) previousMillis = currentMillis;
   break; 

case 1: // ISO2
blinkOff(); 
if(currentMillis - previousMillis > 1000 && currentMillis - previousMillis  2000) previousMillis = currentMillis;
break;

case 2: // ISO 4
blinkOff(); 
if(currentMillis - previousMillis > 2000 && currentMillis - previousMillis  4000) previousMillis = currentMillis;
break;    

case 3: // ISO6
blinkOff(); 
if(currentMillis - previousMillis > 3000 && currentMillis - previousMillis  6000) previousMillis = currentMillis;
break;
case 4: // ISO8
 blinkOff(); 
if(currentMillis - previousMillis > 4000 && currentMillis - previousMillis  8000) previousMillis = currentMillis;
break;
case 5:
verdi2 = 0;
break;
case 6:
verdi2 = 0;
break;
case 7:
verdi2 = 0;
break;
case 8:
verdi2 = 0;
break;
case 9:
verdi2 = 4;
break;
}
break;

case 3: //FM / OC
switch(verdi2) {

  case 0: //FM1
   blinkOff(); 

if(currentMillis - previousMillis >1000) blinkOn();
if(currentMillis - previousMillis > 6000) previousMillis = currentMillis;
   break; 

case 1: // FM2
 blinkOff(); 
if(currentMillis - previousMillis > 1000 && currentMillis - previousMillis  2000 && currentMillis - previousMillis  3000 && currentMillis - previousMillis  8000) previousMillis = currentMillis;
break;

case 2: // FM3
blinkOff(); 
if(currentMillis - previousMillis > 1000 && currentMillis - previousMillis  2000 && currentMillis - previousMillis  3000 && currentMillis - previousMillis  4000 && currentMillis - previousMillis  5000 && currentMillis - previousMillis  8000) previousMillis = currentMillis;
break;    

case 3: // 
verdi2 = 0;
break;
case 4: //
verdi2 = 0;
break;
case 5:
verdi2 = 0;
break;
case 6:
verdi2 = 0;
break;
case 7:
verdi2 = 0;
break;
case 8:
verdi2 = 0;
break;
case 9:
verdi2 = 2;
break;
}
break;


case 4: //Flash
switch(verdi2) {

  case 0: //Fl 4s
if(currentMillis - previousMillis > 0 && currentMillis - previousMillis  500 && currentMillis - previousMillis  4000) previousMillis = currentMillis;
   break; 

case 1: // Fl 6s
 if(currentMillis - previousMillis > 0 && currentMillis - previousMillis  500 && currentMillis - previousMillis  6000) previousMillis = currentMillis; 
break;

case 2: // LF 10s
if(currentMillis - previousMillis > 0 && currentMillis - previousMillis  2000 && currentMillis - previousMillis  10000) previousMillis = currentMillis;
break;    

case 3: // Fl(2) 6s 
if(currentMillis - previousMillis > 0 && currentMillis - previousMillis  500 && currentMillis - previousMillis  1000 && currentMillis - previousMillis  1500 && currentMillis - previousMillis  6000) previousMillis = currentMillis; 
break;
case 4: // Fl(3) 6s 
if(currentMillis - previousMillis > 0 && currentMillis - previousMillis  500 && currentMillis - previousMillis  1000 && currentMillis - previousMillis  1500 && currentMillis - previousMillis  2000 && currentMillis - previousMillis  2500 && currentMillis - previousMillis  6000) previousMillis = currentMillis; 
break;
case 5:
verdi2 = 0;
break;
case 6:
verdi2 = 0;
break;
case 7:
verdi2 = 0;
break;
case 8:
verdi2 = 0;
break;
case 9:
verdi2 = 4;
break;
}
break;

case 5: //Kardinal
switch(verdi2) {

  case 0: //Nord
blinkOff(); 
if(currentMillis - previousMillis > 500 && currentMillis - previousMillis  1000) previousMillis = currentMillis;   
   break; 

case 1: // Øst
 if(currentMillis - previousMillis > 0 && currentMillis - previousMillis  250 && currentMillis - previousMillis  500 && currentMillis - previousMillis  750 && currentMillis - previousMillis  1000 && currentMillis - previousMillis  1250 && currentMillis - previousMillis  5000) previousMillis = currentMillis;  
break;

case 2: // Sør
if(currentMillis - previousMillis > 0 && currentMillis - previousMillis  250 && currentMillis - previousMillis  500 && currentMillis - previousMillis  750 && currentMillis - previousMillis  1000 && currentMillis - previousMillis  1250 && currentMillis - previousMillis  1500 && currentMillis - previousMillis  1750 && currentMillis - previousMillis  2000 && currentMillis - previousMillis  2250 && currentMillis - previousMillis  2500 && currentMillis - previousMillis  2750 && currentMillis - previousMillis  3000 && currentMillis - previousMillis  5000 && currentMillis - previousMillis  10000) previousMillis = currentMillis;  
break;    

case 3: // vest
if(currentMillis - previousMillis > 0 && currentMillis - previousMillis  250 && currentMillis - previousMillis  500 && currentMillis - previousMillis  750 && currentMillis - previousMillis  1000 && currentMillis - previousMillis  1250 && currentMillis - previousMillis  1500 && currentMillis - previousMillis  1750 && currentMillis - previousMillis  2000 && currentMillis - previousMillis  2250 && currentMillis - previousMillis  2500 && currentMillis - previousMillis  2750 && currentMillis - previousMillis  3000 && currentMillis - previousMillis  3250 && currentMillis - previousMillis  3500 && currentMillis - previousMillis  3750 && currentMillis - previousMillis  4250 && currentMillis - previousMillis  4500 && currentMillis - previousMillis  10000) previousMillis = currentMillis; 
break;
case 4: //
verdi2 = 0;
break;
case 5:
verdi2 = 0;
break;
case 6:
verdi2 = 0;
break;
case 7:
verdi2 = 0;
break;
case 8:
verdi2 = 0;
break;
case 9:
verdi2 = 2;
break;
}
break;
case 6: //Kardinal
switch(verdi2) {

  case 0: //Nord
if(currentMillis - previousMillis > 0 && currentMillis - previousMillis  250 && currentMillis - previousMillis  500 && currentMillis - previousMillis  750 && currentMillis - previousMillis  1000 && currentMillis - previousMillis  1250 && currentMillis - previousMillis  2000 && currentMillis - previousMillis  2750 && currentMillis - previousMillis  3000 && currentMillis - previousMillis  3750 && currentMillis - previousMillis  4000 && currentMillis - previousMillis  4750 && currentMillis - previousMillis  5500 && currentMillis - previousMillis  5750 && currentMillis - previousMillis  6000 && currentMillis - previousMillis  6250 && currentMillis - previousMillis  6500 && currentMillis - previousMillis  6750 && currentMillis - previousMillis  8000) previousMillis = currentMillis;
   break; 

case 1: // 
verdi2 = 0; 
break;

case 2: // 
verdi2 = 0;
break;    

case 3: // 
verdi2 = 0;
break;
case 4: //
verdi2 = 0;
break;
case 5:
verdi2 = 0;
break;
case 6:
verdi2 = 0;
break;
case 7:
verdi2 = 0;
break;
case 8:
verdi2 = 0;
break;
case 9:
verdi2 = 0;
break;
}
break;

case 7:
blinkOff(); 
break;

case 8:
blinkOn();
break;
}
}


void blinkOn()
{
analogWrite(ledPin1, 130);
digitalWrite(ledPin2, HIGH);
delay(30);
analogWrite(ledPin1, 255);
}

void blinkOff()
{
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
}