I'm italian so i don't know english very well.
I have a led number display that has 4 input.
Each input control a bit so if i feed the second and the third input at the same time with 24 v the display shows " 6 ".
The model of the display is RS 589-222.
I tried to write this code but editor give me some errors.
don't need the second test condition because you initialize the controlling variable at the start of the loop. There is no way for x not to be greater than 1, nor b not greater than 1. Rewrite as:
for(int x = 2; x < 6; x++){
for(int b = 2; b < 6; b++){
First, you define a[] with 3 elements. Potential problems:
for (int a[3]= B0000; a<10; a++){ // a is an array, so what is "a < 10" supposed to do?
for(int b=2; b<6 && b>1; b++){
for(int c=0; c<4; c++){ // This assumes a[0], a[1], a[2], a[3], but you don't have an a[3]
digitalWrite(b, a[c]); // Very loud explosion when c == 3...
}
}
}
Get rid of the "magic numbers". For example, instead of the constant 6:
#define MAXPIN 6
// more code...
for(int x = 2; x < MAXPIN; x++){
// more code...
for(int b = 2; b < MAXPIN; b++){
While this has no impact on the code, it makes it easier to read and also easier to change if needed. So if you decide to use one more pin, change the #define to 7 and the loop values are automatically changed by the preprocessor pass.
Also, please see Nick Gammon's two posts at the top of this Forum for guidelines on posting here, especially the use of code tags (</>) when posting source code. Also, you often will see code like this rather than your form:
Those are readable text and contain line numbers, and it's less a question of English as your native language, to understand their meaning.
digitalWrite(PIN, state); takes a boolean HIGH / LOW as state, not an int.
Not everything working different than what you expect will give you a compiler error, however.
After you fixed the compiler errors, you'll notice that an Arduino is by far too fast to see any change in your BCD display. (Do you mean this 1 Digit display?)
ElModdy:
I'm italian so i don't know english very well.
I have a led number display that has 4 input.
Each input control a bit so if i feed the second and the third input at the same time with 24 v the display shows " 6 ".
It sounds like your display is a single digit with a BCD (binary coded decimal) input.
BCD is binary, but it only goes from 0 to 9, so if you set the second and third input high, you made this in binary/BCD:
[b]
wire -> 4 3 2 1
state -> 0 1 1 0[/b]
in binary/BCD, 0110 is 6. So I would expect that your display will react like this:
[/tt]Only problem I can see is that you said you are sending it 24 volts. The Arduino board cannot output that voltage directly. You would need some sort of transistor and resistor driver to turn on and off the 24 volt signal based on the 0 or 5 volt TTL level output of the Arduino.
Krupski i want to do what you say.
I use a relè to power my display.
What should i write to increase the number in display every seconds?
Thank you at all
ElModdy:
Krupski i want to do what you say.
I use a relè to power my display.
What should i write to increase the number in display every seconds?
So it is a display that uses BCD encoding on 4 pins to show one digit.
Code maybe somewhat like:
byte pins[]={2,3,4,5};
#define NUMPINS (sizeof(pins))
void setup() {
for(int i=0; i<NUMPINS; i++) pinMode(pins[i], OUTPUT);
}
void loop()
{
for (int a= 0; a<10; a++) // show digits 0 ... 9
{
// set all 4 pins
for (int i=0;i<NUMPINS; i++) digitalWrite(pins[i], bitRead(a,i));
delay(1000); // do a 1 second delay to see the displayed number
}
}
Your display needs 5V input level from the Arduino?
ElModdy:
it doesn't work.
The display shows "random" numbers.
Anyway thank you for the code.
If the display shows numbers, but the numbers are wrong, most likely just the sequence of pins is not declared correctly.
byte pins[]={2,3,4,5};
In this declaration is
pin-2 for bit-0
pin-3 for bit-1
pin-4 for bit-2
pin-5 for bit-3
Perhaps it might help to look into the datasheet and find out which bit has to be connected to which pin.
And then change the pins in the declaration accordingly.
Or just try out all possibilities by try-and-error!
With 4 pins you have 432*1 = 24 possibilities to arrange the pin numbers in a sequence. Only one sequence of pins will show the correct numbers.