This program is supposed to…
- Make the RGB on the LCD flash through a variation of colors using the PWM pins.
- Display some straight forward text on the display.
- Read an input from a pot, and change an interval at which an LED flashes a pattern.
#include <LiquidCrystal.h>
#include <Wire.h>
#define REDLITE 3
#define GREENLITE 5
#define BLUELITE 6
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
// you can change the overall brightness by range 0 -> 255
int brightness = 255;
void setBacklight(uint8_t r, uint8_t g, uint8_t b) {
// normalize the red LED - its brighter than the rest!
r = map(r, 0, 255, 0, 100);
g = map(g, 0, 255, 0, 150);
r = map(r, 0, 255, 0, brightness);
g = map(g, 0, 255, 0, brightness);
b = map(b, 0, 255, 0, brightness);
// common anode so invert!
r = map(r, 0, 255, 255, 0);
g = map(g, 0, 255, 255, 0);
b = map(b, 0, 255, 255, 0);
Serial.print("R = "); Serial.print(r, DEC);
Serial.print(" G = "); Serial.print(g, DEC);
Serial.print(" B = "); Serial.println(b, DEC);
digitalWrite(REDLITE, r);
digitalWrite(GREENLITE, g);
digitalWrite(BLUELITE, b);
}
// This 39kHz loop from http://zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino
/* Modulate pin at 39 kHz for give number of microseconds */
void on(int pin, int time) {
static const int period = 25;
// found wait_time by measuring with oscilloscope
static const int wait_time = 9;
for (time = time/period; time > 0; time--) {
digitalWrite(pin, HIGH);
delayMicroseconds(wait_time);
digitalWrite(pin, LOW);
delayMicroseconds(wait_time);
}
}
void cameraSnap(int pin)
{
// These Timing are from: http://www.bigmike.it/ircontrol/
on(pin,2000);
//This Delay is broken into 3 lines because the delayMicroseconds() is only accurate to 16383. http://arduino.cc/en/Reference/DelayMicroseconds
delayMicroseconds(7830);
delayMicroseconds(10000);
delayMicroseconds(10000);
on(pin,390);
delayMicroseconds(1580);
on(pin,410);
delayMicroseconds(3580);
on(pin,400);
}
int CameraIrPin = 4; // LED connected to digital pin 13
int configPin = 2; // potentiometer to pin analogic 2
int selection = 0; // inizializzo la variabile di attesa
#define LENARRAY 14 // number of element of array
int confArray[LENARRAY] = {0, 5, 10, 15, 20, 24, 25, 30, 35, 40, 45, 50, 55, 60}; // wait time in seconds
long previousMillis = 0;
byte newChar[8] = { //copyraght character
B00000,
B01110,
B10001,
B11111,
B11001,
B11111,
B10001,
B01110
};
void setup()
{
pinMode(CameraIrPin, OUTPUT); // config digital pin as output
lcd.begin(16,2) ; // inizializza LCD
lcd.createChar(0, newChar);
lcd.setCursor(0,1);
lcd.print("By ...");
lcd.write(byte(0));
lcd.setCursor(0,0);
lcd.print(" Intervalometer");
delayMicroseconds(7000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Designed to");
lcd.setCursor(0,1);
lcd.print(" NIKON D SERIES");
delayMicroseconds(6000);
pinMode(REDLITE, OUTPUT);
pinMode(GREENLITE, OUTPUT);
pinMode(BLUELITE, OUTPUT);
brightness = 254;
}
void loop()
{
selection = analogRead(configPin); //read pot value (from 0 to 1023)
selection = map(selection,0, 1023, 1, LENARRAY) ; // resize the value to other like array
lcd.setCursor(0,0) ;
lcd.print("INTERVAL:");
lcd.print(confArray[selection]); //show the set of second
lcd.print(" sec "); // keep this space
lcd.setCursor(0,1);
lcd.print("RELEASE:");
unsigned long currentMillis = millis();
lcd.print(confArray[selection] - ((currentMillis - previousMillis)/1000)); // countdown
//
lcd.print(" "); // clear lcd
// time control
if((currentMillis - previousMillis) > (confArray[selection]*1000)) {
previousMillis = currentMillis; // i save the last shot
cameraSnap(CameraIrPin);
for (int i = 0; i < 255; i++) {
setBacklight(i, 0, 255-i);
delay(5);
}
for (int i = 0; i < 255; i++) {
setBacklight(255-i, i, 0);
delay(5);
}
for (int i = 0; i < 255; i++) {
setBacklight(0, 255-i, i);
delay(5);
}
}
}
It is currently…
-Not displaying text on the display.
-LCD comes up with a dull red, the balanced red, and does not change.
-Using a camera, we cannot see the IR light blinking the pattern it should be at the set time from the pot.
Thanks for any help, this is needed on Tuesday, so any type of suggestion to fix this would be great!
If their are no problems in the program, however, I will continue to look over the hardware, as I am currently.