Jared - IR Controlled Dimmer

/*Purpose:      Use IR remote to adjust brightness of LEDs
 *Date Created: 05/01/2011
 *Author:       Jared Morell
 */

#include <stdio.h>

#define IR_OUT1 4  // ouput 1 from IR decoder (down - dim)
#define IR_OUT2 5  // ouput 2 from IR decoder (up - brighten)
#define opt 6      // option for which pot to use - LOW = 1, HIGH = 2
#define SHTD 10    // shutdown control on POT
#define CS 11      // chip select output to POT
#define CLK 12     // serial clock output to POT
#define SDI 13     // serial data output to POT

byte address = 0;    // specific POT address on digital POT
byte rstlevel = 240; // reset level of output voltage: (241/256)*Vdd
byte pot;            // current level of output voltage: (pot/256)*Vdd

int last_out1val=0;
int last_out2val=0;

void setup(){
  pinMode(SHTD, OUTPUT);
  pinMode(CS, OUTPUT);
  pinMode(CLK, OUTPUT);
  pinMode(SDI, OUTPUT);
 
  pinMode(IR_OUT1, INPUT);
  pinMode(IR_OUT2, INPUT);
  pinMode(opt, INPUT);
 
  digitalWrite(SHTD, HIGH);

  // set pot to mid level and output to POT
  pot = rstlevel;
  sendLevel(pot);

  Serial.begin(9600);
}

// run infinite loop to check for inputs and act accordingly
void loop(){

  int out1val = digitalRead(IR_OUT1);
  int out2val = digitalRead(IR_OUT2);
 
  // if UP has been pressed on remote
  if(out2val == HIGH){
    
    Serial.println("UP");
        
    // increase pot value as long as max hasn't been reached
    if (pot < 255){
      pot=pot+3;
      sendLevel(pot);
      Serial.print("pot = ");
      Serial.println(pot, DEC);
    }
     delay(500);  //delay for when button on remote pressed too long
   }
   
   // if DOWN has been pressed on remote
   if(out1val == HIGH){
      
     Serial.println("DOWN");

     // decrease pot value as long as min hasn't been reached
     if (pot > 0){
       pot=pot-3;
       sendLevel(pot);
       Serial.print("pot = ");
       Serial.println(pot, DEC);
     }
     delay(500);  //delay for when button on remote pressed too long
   }
}

// send information to POT
void sendLevel(byte val){
  byte address = digitalRead(opt);
  digitalWrite(CS, LOW);
  shiftOut(SDI, CLK, MSBFIRST, address);
  shiftOut(SDI, CLK, MSBFIRST, val);
  digitalWrite(CS, HIGH);
}