@CrossRoads:
Correct, he is only doing 1 - 4 in his test pgm, I was getting at masking off possibly floating inputs.
Let' try this
int input = digtalRead(pinx);
switch ( input)
{
case 1 :
{
if(digtalRead(pinx)== 1)
break;
}
}
switch ( input)
{
case 1 :
{
if(input == 1)
break;
}
}
See the difference ?
In first case the pin is read again and processed
In second case the value of input is read only once and evaluated.
It appears that the ctrl ( PINC) changes without being read again.
Is that the case?
Laserbee:
..but it doesn't explain what I am seeing.
your code
int cntrl=PINC;
only reads port C ONCE, The code says read current values on portC, store this value into RAM at address assigned to 'cntrl'.
replace all references to cntrl with (PINC & 0x2F), this will read A0..A5, masking off the inaccessible upper 2 bits of port C.
You were using a stale value for cntrl.
Chuck.
Laserbee:
Looks like I pissed him right off then...
No, it's just this thing I have to do every day called "sleep"
Looks like I pissed him right off then.
If you'd really pissed the moderator off, you'd know it.
This board really needs a thing where a person can be blocked in such a way that they are directed to a form where they have to post some text that includes a pair of code tags, and a "I understand code tags and I promise to use them in future" checkbox.
switch (cntrl) {
case 1:
Serial.print("case is Red"); Serial.println(cntrl);
for (int i=0; i<20; i++) {
digitalWrite(3, HIGH);
delay(50);
digitalWrite(3, LOW);
delay (50);
if (cntrl == 1){break;}
}
break;
…
}
This will toggle pin three once and then exit the switch statement.
You want the loop to exit as soon as 'ctrl' changes, and there's nothing in the loop that is going to change ctrl. But this switch is inside your loop() function, which means it is just going to run over and over. I presume that your loop reads a pin into 'ctrl' near the start of loop(), so the effect will be that the blinking stops as soon as that pin changes.
If you change the == to a !=, then a particular LED will always blink 20 times, and which LED blinks will depend on how ctrl was set at the moment the outer loop() was run.
Thankyou all for your input with this query.
Firstly,
// I promise to use code tags in future !
Secondly,
Thankyou Paul Murray for explaining what I am seeing! What you have pointed out makes proper sense now I see it and I would never have got that without it being pointed out. This C malarky is a tough old boot to master when you are as thick as shit - like wot I is!
Thankyou all again. x