Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

SELECT CASE END SELECT Equals IF THEN?
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions
View previous topic :: View next topic  
Author Message
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 222
Location: D.F.

mexico.gif
PostPosted: Mon May 01, 2017 7:26 pm    Post subject: SELECT CASE END SELECT Equals IF THEN? Reply with quote

Helo all!! Very Happy

I'm doing an exercise just about SELECT-CASE with IF THEN correct me if I'm wrong. Laughing

Code:
Do
  Lightlevel = Getadc(0)
  Select Case Lightlevel
   Case 102 To 199 : Portb = &B01111111
   Case 200 To 399 : Portb = &B10111111
   Case 400 To 499 : Portb = &B11011111
   Case 500 To 599 : Portb = &B11101111
   Case 600 To 699 : Portb = &B11110111
   Case 700 To 799 : Portb = &B11111011
   Case 800 To 899 : Portb = &B11111101
   Case 900 To 1023 : Portb = &B11111110
  End Select
Loop
End



Do not mark me a mistake, correct me if you're okay or not?


Code:
Do
  Lightlevel = Getadc(0)
   If Lightlevel > 199 Then Portb = &B01111111
   Else
   If Lightlevel > 200 And Lightlevel < 399 Then Portb = &B10111111
   Else
   If Lightlevel > 400 And Lightlevel < 499 Then Portb = &B11011111
   Else
   If Lightlevel > 500 And Lightlevel < 599 Then Portb = &B11101111
   Else
   If Lightlevel > 600 And Lightlevel < 699 Then Portb = &B11110111
   Else
   If Lightlevel > 700 And Lightlevel < 799 Then Portb = &B11111011
   Else
   If Lightlevel > 800 And Lightlevel < 899 Then Portb = &B11111101
   Else
   If Lightlevel < 1023 Then Portb = &B11111110
   End If
Loop
End


Rolling Eyes Rolling Eyes
Back to top
View user's profile
albertsm

Administrator



Joined: 09 Apr 2004
Posts: 5034
Location: Holland

blank.gif
PostPosted: Mon May 01, 2017 8:06 pm    Post subject: Reply with quote

code like this :
Select Case Lightlevel
Case 102 To 199 : Portb = &B01111111
Case 200 To 399 : Portb = &B10111111

translates to:
if Lightlevel >=102 and LightLevel <200 then
Portb = &B0111_1111
elseif lightlevel >=200 and lightlevel <400 then
Portb = &B1011_1111
etc.

you should check the help and samples.

_________________
Mark
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 222
Location: D.F.

mexico.gif
PostPosted: Tue May 02, 2017 2:59 am    Post subject: Reply with quote

Hello!!
I already read Bascom's help.

These are the results but it does not work is this or are you wrong?

Code:
Do
  Lightlevel = Getadc(0)
   If Lightlevel > 102 And Lightlevel < 200 Then
   Portb = &B01111111
   Elseif Lightlevel > 199 And Lightlevel < 400 Then
   Portb = &B10111111
   Elseif Lightlevel > 399 And Lightlevel < 500 Then
   Portb = &B11011111
   Elseif Lightlevel > 499 And Lightlevel < 600 Then
   Portb = &B11101111
   Elseif Lightlevel > 599 And Lightlevel < 700 Then
   Portb = &B11110111
   Elseif Lightlevel > 699 And Lightlevel < 800 Then
   Portb = &B11111011
   Elseif Lightlevel > 799 And Lightlevel < 900 Then
   Portb = &B11111101
   Elseif Lightlevel < 899 And Lightlevel > 1022 Then
   Portb = &B11111110
   Else
   End If
Loop
End


Is it right or not? Do not arrest Leds_0 Question Question

Code:
Elseif Lightlevel < 899 And Lightlevel > 1022 Then
   Portb = &B11111110
   Else
   End If
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 222
Location: D.F.

mexico.gif
PostPosted: Tue May 02, 2017 3:27 am    Post subject: Reply with quote

Hi!! Albertsm
Very Happy Very Happy Very Happy Very Happy

Code:
Elseif Lightlevel > 899 And Lightlevel > 1022 Then
   Portb = &B11111110
   Else
   End If


I already corrected ... It works !!! Question?

Wink Wink Wink
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 222
Location: D.F.

mexico.gif
PostPosted: Tue May 02, 2017 1:24 pm    Post subject: Reply with quote

Very Happy Hi Very Happy

I have a question which of the two is correct without ELSE or ELSE?

Without ELSE?

Code:
Elseif Lightlevel > 899 And Lightlevel > 1022 Then
   Portb = &B11111110
   End If
Loop
End


With ELSE?

Code:
Elseif Lightlevel > 899 And Lightlevel > 1022 Then
   Portb = &B11111110
   Else
   End If
Loop
End


Both works fine !! Very Happy Very Happy
Back to top
View user's profile
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 551

germany.gif
PostPosted: Tue May 02, 2017 2:07 pm    Post subject: Reply with quote

this is absolutly nonsense...

Code:

Elseif Lightlevel > 899 And Lightlevel > 1022 Then
 

_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 222
Location: D.F.

mexico.gif
PostPosted: Tue May 02, 2017 2:27 pm    Post subject: Reply with quote

Why? But it works fine !!
Back to top
View user's profile
six1

Bascom Expert



Joined: 27 Feb 2009
Posts: 551

germany.gif
PostPosted: Tue May 02, 2017 2:58 pm    Post subject: Reply with quote

You didn't understand the working of "if", "elseif", "else" and maybe also not "boolean operators".


something like:

if 1=0 then....

else
...
endif

is working or better: will be compiled, but makes no sense at all.

_________________
For technical reasons, the signature is on the back of this message.
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 222
Location: D.F.

mexico.gif
PostPosted: Tue May 02, 2017 3:07 pm    Post subject: Reply with quote

Very Happy is working or better: will be compiled, but makes no sense at all. Very Happy
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 222
Location: D.F.

mexico.gif
PostPosted: Tue May 02, 2017 3:12 pm    Post subject: Reply with quote

Printpix52 wrote:
Very Happy is working or better: will be compiled, but makes no sense at all. Very Happy


So correct me I want to see them working fine. Shocked
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 222
Location: D.F.

mexico.gif
PostPosted: Tue May 02, 2017 5:16 pm    Post subject: Reply with quote

Printpix52 wrote:
Very Happy Hi Very Happy

I have a question which of the two is correct without ELSE or ELSE?

Without ELSE?

Code:
Elseif Lightlevel > 899 And Lightlevel > 1022 Then
   Portb = &B11111110
   End If
Loop
End


With ELSE?

Code:
Elseif Lightlevel > 899 And Lightlevel > 1022 Then
   Portb = &B11111110
   Else
   End If
Loop
End


Both works fine !! Very Happy Very Happy




For more conditions is this.

Code:
If Condicion_0 Then
     Instrucion_0
  Elseif Condicion_1 Then
     Instrucion_1
  Elseif Condicion_2 Then
     Instruccion_2
     .....
     .....
     .....
     .....
  Elseif Condicion_7 Then
    Instruccion_7
  End If

 


So that's the way it is written.

Code:
Do
  Lightlevel = Getadc(0)
   If Lightlevel > 102 And Lightlevel < 200 Then
   Portb = &B01111111
   Elseif Lightlevel > 199 And Lightlevel < 400 Then
   Portb = &B10111111
   Elseif Lightlevel > 399 And Lightlevel < 500 Then
   Portb = &B11011111
   Elseif Lightlevel > 499 And Lightlevel < 600 Then
   Portb = &B11101111
   Elseif Lightlevel > 599 And Lightlevel < 700 Then
   Portb = &B11110111
   Elseif Lightlevel > 699 And Lightlevel < 800 Then
   Portb = &B11111011
   Elseif Lightlevel > 799 And Lightlevel < 900 Then
   Portb = &B11111101
   Elseif Lightlevel > 899 And Lightlevel > 1022 Then
   Portb = &B11111110
   End If
Loop
End


Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Very Happy Wink
Back to top
View user's profile
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 222
Location: D.F.

mexico.gif
PostPosted: Thu May 04, 2017 2:59 am    Post subject: Re: SELECT CASE END SELECT Equals IF THEN? Reply with quote

Printpix52 wrote:
Helo all!! Very Happy

I'm doing an exercise just about SELECT-CASE with IF THEN correct me if I'm wrong. Laughing

Code:
Do
  Lightlevel = Getadc(0)
  Select Case Lightlevel
   Case 102 To 199 : Portb = &B01111111
   Case 200 To 399 : Portb = &B10111111
   Case 400 To 499 : Portb = &B11011111
   Case 500 To 599 : Portb = &B11101111
   Case 600 To 699 : Portb = &B11110111
   Case 700 To 799 : Portb = &B11111011
   Case 800 To 899 : Portb = &B11111101
   Case 900 To 1023 : Portb = &B11111110
  End Select
Loop
End



Do not mark me a mistake, correct me if you're okay or not?


Code:
Do
  Lightlevel = Getadc(0)
   If Lightlevel > 199 Then Portb = &B01111111
   Else
   If Lightlevel > 200 And Lightlevel < 399 Then Portb = &B10111111
   Else
   If Lightlevel > 400 And Lightlevel < 499 Then Portb = &B11011111
   Else
   If Lightlevel > 500 And Lightlevel < 599 Then Portb = &B11101111
   Else
   If Lightlevel > 600 And Lightlevel < 699 Then Portb = &B11110111
   Else
   If Lightlevel > 700 And Lightlevel < 799 Then Portb = &B11111011
   Else
   If Lightlevel > 800 And Lightlevel < 899 Then Portb = &B11111101
   Else
   If Lightlevel < 1023 Then Portb = &B11111110
   End If
Loop
End


Rolling Eyes Rolling Eyes


Helo all!! Very Happy Very Happy Very Happy

I already solved this, I can do it, I'm very happy !! Very Happy Very Happy Very Happy

Code:
Do
  Lightlevel = Getadc(0)
   If Lightlevel > 102 And Lightlevel < 200 Then
   Portb = &B01111111
   End If
   If Lightlevel > 199 And Lightlevel < 400 Then
   Portb = &B10111111
   End If
   If Lightlevel > 399 And Lightlevel < 500 Then
   Portb = &B11011111
   End If
   If Lightlevel > 499 And Lightlevel < 600 Then
   Portb = &B11101111
   End If
   If Lightlevel > 599 And Lightlevel < 700 Then
   Portb = &B11110111
   End If
   If Lightlevel > 699 And Lightlevel < 800 Then
   Portb = &B11111011
   End If
   If Lightlevel > 799 And Lightlevel < 900 Then
   Portb = &B11111101
   End If
   If Lightlevel > 899 And Lightlevel > 1022 Then
   Portb = &B11111110
   End If
Loop
End



I am very happy I like bascom avr !!! Very Happy Very Happy Very Happy Wink Wink Wink
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 923
Location: France

france.gif
PostPosted: Thu May 04, 2017 1:54 pm    Post subject: Reply with quote

the big difference between if--endif and select case

let us suppose your level is 103

your program read all line and spend a lot of time for nothing

with if--- endif or if ---elseif --endif

You can do that but add "Exit do" after each choice


with select case
the program goes directly to the good line and exit of the loop after.

JP Wink
Back to top
View user's profile Visit poster's website
Printpix52

Bascom Member



Joined: 18 Jun 2014
Posts: 222
Location: D.F.

mexico.gif
PostPosted: Thu May 04, 2017 3:37 pm    Post subject: Reply with quote

Hello!! Dubai and the probe does not work. Sad
Back to top
View user's profile
Duval JP

Bascom Member



Joined: 22 Jun 2004
Posts: 923
Location: France

france.gif
PostPosted: Thu May 04, 2017 6:04 pm    Post subject: Reply with quote

would you like explain what you want to do Question Rolling Eyes
jp
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Unsupported versions All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum