I don't have another gasket to pop, but I appreciate the concern
I am just mystified that the order of doing things is such a difficult concept to grasp.
SETALLDIGITAL setsallpinsto digital*.
If you set up a pin for analog input (i.e., as an ADC input), shouldn't it be obvious that following that with SETALLDIGITAL undoes everything you just did? That's why I attempted to get MrDEB to think about what actually is going on**, but I know that's never going to happen.
I got my LEDs to cooperate with the ADC
now back to the timer and get that to play with the ADC
here is what I came up with and seems to work as planed. Just don't spill your coffee or ? on your keyboard when you read my code. going to use the counter in another routine
Code:
Sub Stage()
ADVal_1 = ADC.Read(0)
If ADVal_1<=400 Then //pre stage
blue1=0
blue2=1
counter=1
EndIf
If ADVal_1<=300 Then //staged
blue2=1
blue1=1
counter=2
EndIf
If ADVal_1<200 //deep stage
Then
blue1=1
blue2=0
counter =3
EndIf
End Sub
{
Ian, it wouldn't surprise me in the slightest if there are chips where you have to do that.
It's always worked for me (when I did it by mistake), but then again I usually try to set them the right way around in the first place!
Sub Stage()
ADVal_1 = ADC.Read(0)
If ADVal_1<=400 Then //pre stage
blue1=0
blue2=1
counter=1
EndIf
If ADVal_1<=300 Then //staged
blue2=1
blue1=1
counter=2
EndIf
If ADVal_1<200 //deep stage
Then
blue1=1
blue2=0
counter =3
EndIf
End Sub
{
This code will appear to work ok, but it's going to result in (very brief) extraneous flashes. It demonstrates a really poor understanding of what's going in. Imagine that!
Say the ADC value is 100. What happens in this loop?
100 is less than 400 so
Blue1 = 0
Blue2 = 1
Immediately thereafter, 100 is less than 300 so
Blue1 = 1
Blue2 = 1
And Immediately after that, 100 is less than 200 so
Blue1 = 1
Blue2 = 0
You really want each test to respond to exactly one condition.
Use a select/case statement
Code:
Select ADCVal_1
Case > 400
'do nothing
Case > 300
Blue1 = 0
Blue2 = 1
Case > 200
Blue1 = 1
Blue2 = 1
Case <=200
Blue1 = 1
Blue2 = 0
End Select
In a select/case statement, the first case statement that is TRUE is the only one that will be executed. All others are ignored. The key thing to remember is the order. Each test must be arranged so that only the desired condition can trigger it.
Believe me, I am well aware that MrDEB will likely ignore this. I post it in the hopes that others may benefit from it.