Hey Arduino-Crew,
I need some urgent help for a project.
We built a device that detects empty beer cups and shows the number on a display.
This is our project page if you want to know more: Garbage Bar Arco do Cego
This is the sensor we use:
Thats the Display we use:
The problem that we have is, that the last digit of the 4 is much brighter than the other ones. We are pretty sure that the problem is related to the code and is not a hardware problem.
This is the first time for me writing a code for an arduino so I apologize if its too messy or too long.I shortend it a little, the whole code is attached.
I think that the problem is in the switch statement in the pickDigit function. We tried changing it and made the default case related to another digit and then that one would be the brightest.
If you just set all digits to HIGH in the pickdigit function, the display shows 4 times the same digit.
I am gonna attach some pictures, so you see what I mean.
We would be really grateful if anyone could help us!
We are launching tomorrow (even if we don't get the displays perfect), so if you are in Lisbon, come by and have a beer with us ![]()
Thanks a lot!
Mona
Here is the code:
#include <EEPROM.h>
///LEFT////
//segments
int a = 11;
int b = 7;
int c = 4;
int d = 3;
int e = 13;
int f = 10;
int g = 5;
//digitos
int d1 = 12;
int d2 = 9;
int d3 = 8;
int d4 = 6;
//EEPROM
int ncups_left;
int b1=0;
int b2=1;
//Sensors
int ls = 40; //left sensor pin
int l_sensorCounter = 0; // counter for the left sensor
int l_sensorState = 0; // current state of the left sensor
int l_lastsensorState = 0; // previous state of the left sensor
void setup()
{
Serial.begin(9600);
ncups_left = 256*EEPROM.read(b1)+EEPROM.read(b2);
///LEFT SIDE///
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode(d1, OUTPUT);
pinMode(d2, OUTPUT);
pinMode(d3, OUTPUT);
pinMode(d4, OUTPUT);
pinMode(ls,INPUT); //SENSOR
}
void loop()
{
////////////////////Left Hole///////////////////
l_sensorState = digitalRead(ls);
// compare the sensorState to its previous state
if (l_sensorState != l_lastsensorState) {
// if the state has changed, increment the counter
if (l_sensorState == HIGH) {
// if the current state is HIGH then the sensor
// went from off to on:
l_sensorCounter++;
ncups_left++;
} else {
}
// Delay a little bit to avoid bouncing
delay(50);
}
// save the current state as the last state,
//for next time through the loop
l_lastsensorState = l_sensorState;
//ncups_left=l_sensorCounter;
//Serial.println(ncups_left);
//EEPROM - stuff
//left hole
int val1 = ncups_left / 256;
int val2 = ncups_left % 256;
EEPROM.write(b1, val1);
EEPROM.write(b2, val2);
clearLEDs();
pickDigit(1);
pickNumber((ncups_left/1000)%10);
clearLEDs();
pickDigit(2);
pickNumber((ncups_left/100)%10);
clearLEDs();
pickDigit(3);
pickNumber((ncups_left/10)%10);
clearLEDs();
pickDigit(4);
pickNumber((ncups_left)%10);
}
void pickDigit(int x)
{
digitalWrite(d1, LOW);
digitalWrite(d2, LOW);
digitalWrite(d3, LOW);
digitalWrite(d4, LOW);
switch(x)
{
case 1:
digitalWrite(d1, HIGH);
break;
case 2:
digitalWrite(d2, HIGH);
break;
case 3:
digitalWrite(d3, HIGH);
break;
default:
digitalWrite(d4, HIGH);
break;
}
}
void pickNumber(int x)
{
switch(x)
{
default: zero(); break;
case 1: one(); break;
case 2: two(); break;
case 3: three(); break;
case 4: four(); break;
case 5: five(); break;
case 6: six(); break;
case 7: seven(); break;
case 8: eight(); break;
case 9: nine(); break;
}
}
void clearLEDs()
{
digitalWrite(a, HIGH);
digitalWrite(b, HIGH);
digitalWrite(c, HIGH);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void zero()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
}
void one()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void two()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void three()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void four()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void five()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void six()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void seven()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void eight()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void nine()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
meea_testex_grupo7.ino (9.35 KB)


