Sunpak AP-200W Arduino Hack (Part 4)

I have made some improvements to the firmware i will leave the code below but first some  of the changes.

Now Limit switches are identified.IR Receivers are working and have decoding capabilities.I have added “Mode” support or IR learning via serial Monitor.Error codes via Power LED blinking. 

/*
Sunpak AP-200W revised Arduino Fimware.
now all LEDs’ are working.
This Project is available on my Blog
https://danielfrausto.wordpress.com/sunpak-ap-200w-arduino-hack/
written by: Daniel Frausto
January 20,2016
*/
#include <IRremote.h>

//=================================================================
// Define pins.
//IC 1&2 are Toshiba TA8409S, In1 = Pin1 , In 2 = Pin 9
//IC 1 =Tilt Driver, IC2 = Pan Driver
//=================================================================
#define sw1 1 //pwr Switch
#define sw2 2 //Tilt UP-Limit
#define sw3 3 //Tilt Down-limit
#define sw4 4 //Pan Left-Limit
#define sw5 5 //Pan Right-Limit
#define ic2_2 6 //ic2 In2 PAN
#define ic2_1 7 //ic2 In1 PAN
#define ic1_1 8 //ic1 In2 TILT
#define ic1_2 9 //ic1 In1 TILT
#define motor_enable 10 //Enables motor divers and Motor LED
#define status_led 12 //IR status LED, Motors have to be enabled
#define pwr_led 13 //Power LED Status

int mode = 0;

int RECV_PIN = A0;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
//=================================================================
//Set Input Buttons,Switches and IR Sensors
//=================================================================
pinMode(sw1, INPUT_PULLUP); //Power Switch
pinMode(sw2, INPUT_PULLUP); //Tilt UP-Limit
pinMode(sw3, INPUT_PULLUP); //Tilt Down-limit
pinMode(sw4, INPUT_PULLUP); //Pan Left-Limit
pinMode(sw5, INPUT_PULLUP); //Pan Right-Limit
//=================================================================
// Set Output Pins/LEDs’
//=================================================================
pinMode(ic2_2, OUTPUT);
pinMode(ic2_1 , OUTPUT);
pinMode(ic1_1 , OUTPUT);
pinMode(ic1_2 , OUTPUT);
pinMode(motor_enable, OUTPUT);
pinMode(status_led, OUTPUT);
pinMode(pwr_led, OUTPUT);
digitalWrite(motor_enable, 1);
boot();
digitalWrite(motor_enable, 0);

Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver

}
//===================================================================
// Main Program
//===================================================================
void loop()
{
digitalWrite(pwr_led, 1);
digitalWrite(motor_enable, 1);
digitalWrite(status_led, 1);
//pan_left();
//err();
//digitalWrite(ic2_2, 0);
//digitalWrite(ic2_1, 1);
if (irrecv.decode(&results))                       // IR signal received
{
translateIR();
irrecv.resume(); // receive  next IR Code
}
}

void translateIR()
{
switch (results.value)
{

case 0x544DD9C:      //Panasonic IR Remote Mode Button
mode=1;
Serial.println(” Mode”);
break;

delay(500);
} //Done

while (mode == 1){
ir_decode();
}
}

void ir_decode()
{
decode_mode();

if (irrecv.decode(&results)) {

Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
}

//==========================================
// LED Blink Codes
//==========================================

void boot() // Boot sequence starting.
{
blink(status_led, 2, 100);
}
void err_01() // Low Battery.
{
blink(status_led, 3, 200);
}
void err_02()
{
blink(status_led, 6, 200);
}

void decode_mode() // Device is in IR Decode Mode
{
blink(pwr_led, 6, 200);
}

void ir_recieved()
{
blink(status_led, 1, 200);
}

void pan_left()
{
digitalWrite(motor_enable, 1);
digitalWrite(ic2_2, 0);
digitalWrite(ic2_1, 1);
delay(500);
digitalWrite(ic2_2, 0);
digitalWrite(ic2_1, 0);
}

void pan_right()
{
digitalWrite(motor_enable, 1);
digitalWrite(ic2_2, 1);
digitalWrite(ic2_1, 0);
delay(500);
digitalWrite(ic2_2, 0);
digitalWrite(ic2_1, 0);
}
//==========================================
// Blinks Status Led
//==========================================
void blink(int whatPin, int howManyTimes, int milliSecs) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) {
digitalWrite(whatPin, HIGH);
delay(milliSecs / 2);
digitalWrite(whatPin, LOW);
delay(milliSecs / 2);
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s