First of all thanks to anyone who takes the time to read and respond to this.
I am using the ATiny85 USB board to make and control functions in a Model Railway(Railroad) dcc system. The basis of this sytem was developed by a guy in the netherlands Ruud Boer and the link to this topic is given here:
Essentially I am trying to turn on and off two bi-colour (red/white) 5v two lead-out leds. As a start I used the following simple piece of code.
int leds1=0;
int leds2=3;
int leds3=1;
int leds4=4;
//All pins are capable of Digital output, though P5 is 3 V at HIGH instead of 5 V
// pinMode(0, OUTPUT); //0 is P0, 1 is P1, 2 is P2, etc. - unlike the analog inputs, for digital outputs the pin number matches.
void setup()
{
pinMode (leds1, OUTPUT);
pinMode (leds2, OUTPUT);
pinMode (leds3, OUTPUT);
pinMode (leds4, OUTPUT);
}
void loop()
{
digitalWrite(leds1, HIGH);
digitalWrite(leds2, LOW);
digitalWrite(leds3, HIGH);
digitalWrite(leds4, LOW);
delay(5000);
digitalWrite(leds2, HIGH);
digitalWrite(leds1, LOW);
digitalWrite(leds4, HIGH);
digitalWrite(leds3, LOW);
delay(5000);
}
And sure enough this turns the red and white on in turn, with a slight delay and since I did not use any current limiting resistors I got good bright light when the leds lit.
So now I needed to integrate this simple code into the more complex code which involves the digital command and control. The base code is attached as the file Base code:
I then modified the base code to the version Class 29 and the code works but there are clearly problems which i do not understand and I could do with some help to try and find where the problem lies:
I am using Pins 0 & 3 and 1 & 4 as the two pairs to Output.
How it then works is that I hook the ATTiny through a circuit board which supplies 5v to the ATTiny85 and the dcc signal from the track through an optocoupler circuit. As illustrated in the picture. When F9 is activated the LED goes red but with no real brightness when F10 is activated then the white light is as expected. The same is true for the f11 and F12 functions. If I reverse the polarity of the leds then the red is bright and the white dim. It would appear that the problem is in the code not the circuit. Clearly I should have much the same brightness in both conditions.
The two aspect I do not understand are:
At line 91 and 112 I have a condition that if both f9 and f10 and f11 and f12 are both activated set all values to low. This is to avoid trying to light both of the colours at the same time.
if ((Func[2]&B00000001) && (Func[2]&B00000010)) {
digitalWrite(F9_pin,LOW);
digitalWrite(F10_pin,LOW);
That does not appear to work can anyone see what error I have made in the code?
What is causing the led to be dim. In the F9 condition activated i.e Pin 0 HIGH and Pin 3 LOW and also in the F11 condition Pin 1 HIGH and Pin 4 LOW the leds are dim and the measured volatge is about 1v not 5v. It worksin the simple code why not in the more complex code scenario.
Any help or insight would be greatly appreciated
Base code.pdf (69.5 KB)
Class 29.pdf (70.4 KB)