Arduino Board and Code.
The arduino is a great piece of kit with a very helpful community. This code is for 4 potentiometers, each controlling the intensity of one LED via PWM 8bit control. This then links back to the laptop via a push button to give a readout of the values via the serial port. In this instance, I have Yellow, White, green and Orange LEDs to try to match the colour of the tallow candlelight.
Anyway, here is the code: (The bits with “//” before them is an explanation of what the code means. I usually write this in to my code to help me understand wheat each line does. It helps when trying to fix errors too!)
//set up pots
int pot1 = 0; //These are the analogue numbers on the arduino board
int pot2 = 1;
int pot3 = 2;
int pot4 = 3;
int pot5 = 4;
int button = 5;
//set up LEDs
int LED1 = 9; //These are the digital numbers on the arduino board
int LED2 = 10;
int LED3 = 11;
int LED4 = 3;
int LED5 = 5;
int oneVal = 0; // Variables to store the input from the potentiometers
int twoVal = 0;
int threeVal = 0;
int fourVal = 0;
int fiveVal = 0;
int buttonval = 0;
pinMode(LED1, OUTPUT); // sets the digital pins as output
Serial.begin(9600); // Open serial communication for reporting
oneVal = (analogRead(pot1)/4); // read input pins, convert to 0-255 scale
twoVal = (analogRead(pot2)/4);
threeVal = (analogRead(pot3)/4);
fourVal = (analogRead(pot4)/4);
fiveVal = (analogRead (pot5)/4);
analogWrite(LED1, oneVal); // Send new values to LEDs
buttonval = analogRead(button); //Test Button Pin for high or low
if (buttonval>1000) // Is button pin at 5v or 0?
delay(1000); //delay for 1 second so that you only get one line of data.
Serial.print(“Yellow: “); // …then print the values.
Serial.print(” White: “); //call this white
Serial.print(twoVal); //print the value for white
Serial.print(” Green: “);
Serial.print(” Orange: “);
Serial.print(” Unused: “);