Help please

Forum for problems or queries regarding other Flowcode Components. Eg LEDs, Switches, LCD, Gfx LCD etc

Moderators: Benj, Mods

stevel
Posts: 19
Joined: Sat Sep 05, 2009 2:18 pm
Contact:

Help please

Postby stevel » Tue Sep 22, 2009 5:02 pm

Having problems with my project having to reset micro for the switches to work first time. i want it to do when switch 1 is pressed to do the leds on and when switch 2 is pressed do led pattern i am sending my flow chart can you look at this please and alter it if needed. i am not sure wat to do as i am very new to flowcode
Attachments
leds.fcf
(7 KiB) Downloaded 212 times

Spanish_dude
Posts: 594
Joined: Thu Sep 17, 2009 7:52 am
Location: Belgium
Has thanked: 63 times
Been thanked: 102 times
Contact:

Re: Help please

Postby Spanish_dude » Tue Sep 22, 2009 6:52 pm

Hi stevel,

I downloaded your program, and I saw a few things that aren't correct.

First one:
To read the switches (input on PORT A) is ok, but you can use the macro instead of the input icon to read the state of a switch. You'll need to use the ReadState() function. If you use this macro, you need to "tell" the macro witch switch you want the read. Ex.: for the first switch then you need to write '0', for the seconde one you need to write '1', etc. You also need to write a variable, so that the microcontroller can "save" the state of the switch. Ex.: for switch 0 use a variable named switch_0.

If you want to use the input PORT A icon and use 2 switches, you can erase the if-then-else switch = 3 and switch = 4.

Second one:
Your if-then-else aren't correct. If you use the macro and use a variable ex. switch_0 then your if-then will look like this: If (switch_0 = 1) then "all leds on" (= output PORT B high) else "nothing happens". For the second switch use the same if-then-else but now you'll change the variable name switch_0 by ex. switch_1.

You only need 2 if-then-else because you only use 2 switches.

Third one:
You use 'while (1)' when you want to 'activate' your LED's. A while (1) is a loop that will never stop. So you need to change that.
If you want to turn your LED's on, you don't need the loop, the icon PORT B = 255 will activate the LED's.
For your "led pattern" try to turn on and off the LED 5 times with a 'loop count'.

I uploaded two examples for you. One with the macro and another one with the input PORT A icon.
I hope you understand what I wrote above.
Attachments
leds.fcf
input PORT A icon
(6.5 KiB) Downloaded 230 times
leds_1.fcf
Macro Icon
(7 KiB) Downloaded 226 times

kersing
Valued Contributor
Valued Contributor
Posts: 1873
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 530 times
Been thanked: 1040 times
Contact:

Re: Help please

Postby kersing » Tue Sep 22, 2009 7:04 pm

stevel wrote:Having problems with my project having to reset micro for the switches to work first time. i want it to do when switch 1 is pressed to do the leds on and when switch 2 is pressed do led pattern i am sending my flow chart can you look at this please and alter it if needed. i am not sure wat to do as i am very new to flowcode


There is no need to post the same question multiple times. Anyway, see my comment at your other posting.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis