Hello all,
I am new to this whole Arduino tech and coding, so please be gentle.
I purchased a Kingbright 3 x 7 segment LED display:
http://uk.farnell.com/kingbright/bc56-11surkwa/display-led-0-56-red-com-cathode/dp/2335764
now, to test this out, i wrote a bit of code :
//int pinArray[] = {26, 31, 30, 29, 39, 49, 48, 47, 46, 36};
int pinArray[] = {26, 27, 28, 29, 30, 31, 32, 36, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52};
int count = 0;
int timer = 100;
void setup(){
for (count=0;count<21;count++) {
pinMode(pinArray[count], OUTPUT);
}
}
void loop() {
for (count=0;count<20;count++) {
digitalWrite(pinArray[count], HIGH);
delay(timer);
digitalWrite(pinArray[count + 1], HIGH);
delay(timer);
digitalWrite(pinArray[count], LOW);
delay(timer);
digitalWrite(pinArray[count + 1], LOW);
}
}
Basic, but it does the job of cycling through each LED checking that it works etc.
Now, i have moved on to another project where i want the segment display to show a number when a code is received:
this code is here:
#include <IRremote.h>
int recvLED = 22;
int recvPin = 13;
IRrecv irReciver(recvPin);
decode_results results;
// Defining the pins for the 3X7 segment display
int threesegment[21] = { 26, 27, 28, 29, 30, 31, 32, 36, 37, 38, 39, 40, 41, 42, 46, 47, 48, 49, 50, 51, 52 };
// Initializing the digits array
const unsigned long digits[][21] = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0}, // Digit 1
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1}, // Digit 2
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1}, // Digit 3
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1}, // Digit 4
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1}, // Digit 5
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1}, // Digit 6
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0}, // Digit 7
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1}, // Digit 8
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1}, // Digit 9
{ 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0}, // Power button (ON)
{ 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1} // Program
};
const unsigned long decodeSIG[] = {
0xB47, // digit 1
0x80B47, // digit 2
0x40B47, // digit 3
0xC0B47, // digit 4
0x20B47, // digit 5
0xA0B47, // digit 6
0x60B47, // digit 7
0xE0B47, // digit 8
0x10B47, // digit 9
0xA8B47, // Power button
0x7AB47, // Program
};
unsigned long lastTime = 0;
void setup()
{
pinMode(recvLED, OUTPUT); //Configue the recvLED pin as an OUTPUT pin
digitalWrite(recvLED, LOW); //Leave the LED off as we start
Serial.begin(9600); // Initialize the serial port with a baud rate of 9600 bps
irReciver.enableIRIn(); // Start the receiver
for (int i=0; i<11; i++)
{
pinMode(threesegment[i], OUTPUT); //Configure all pins in the 3X7 segments display as OUTPUT
}
}
void loop()
{
unsigned long recv_value;
if (irReciver.decode(&results)) {
recv_value = results.value;
if ( recv_value != 0xFFFFFFFF ) //Ignore the 0x00 values recived as a result of pressing and holding a button on the remote for long
{
// Blink the LED each time a button is pressed
digitalWrite(recvLED, HIGH);
delay(10);
digitalWrite(recvLED, LOW);
// Output the decoded hash value to th serial monitor. This is for debugging purposes only.
Serial.println(recv_value, HEX);
Serial.println(results.value);
//Iterate through the decoded hash array values to find a match
for (int i=0; i<11; i++)
{
if ( recv_value == decodeSIG[i] ) // If the received value matches one of the values in the hash array
{
lastTime = millis(); // Start power saving delay timer
for (int j=0; j<=21; j++)
//Set the relevant segments HIGH or LOW as defined in the digits[][] double array
digitalWrite(threesegment[j], digits[i][j]);
break; // Exit from the inner loop as we have now toggled all required segments to display the appropriate value
}
}
}
irReciver.resume(); // Read the next value
}
// To save power switch off all segments if 5 seconds has elapsed since
if ( millis() - lastTime >= 5000 )
{
for (int k=0; k<=21; k++)
digitalWrite(threesegment[k], LOW);
lastTime = 0; // Reset the power saving delay timer to zero '0'
}
}
Now, the code works fine from what i can see but the Arduino Mega 2560 is behaving in an odd fashion.
All of the LEDs in segment 1 of three (the one on the left) is showing up the correct brightness.
SOME of the segment 2 LED's (I.e The middle segment) are bright, and some are very dim
ALL of the segment 3 LED's (one on the right) are all very dim...
Now, if i pull out the jump wire from pin 26 on the board (one that shows up full brightness) and relocate it to a pin on the Display that is DIM, then the DIM segment, becomes full brightness.
so this must be something to do with the Arduino Itself... BUT if i run the code to test each pin, i have no problem at all and they all show full brightness.......
Can anyone shed some light on this (pun not intended !)
thanks
Mutley
EDIT
I have pulled out my trusty DMM and it looks like im getting 1.67v on all the DIM LED's and 4.3v on all the bright LED's....
Any reason why ? I am using the Digital Output pins on the Mega board