Hi,
Name is Jeff - I am new to this product and am giving it a try with flowcode v6 for pic (8 bit) I am using a pic16f690 and the concept of the project is easy but after watching flowcode training videos for days and days now, I am more confused than ever.
Here is the concept – you have 1 push button that is momentary and 8 leds. When you are holding down the button, led 1 lights for as long as you are holding it. When you let the button go, nothing lights. When you hit the button (and hold) again, led 2 lights for as long as you hold it. Rinse and repeat for all leds. This is a concept so it can be 50 leds or 2 leds but you get the idea.
I have seen people use interrupts, macro component calls, and switches to accomplish something similar. My question: I was hoping someone could truly explain these flowcode items in a way that is related to this concept project so that I may better understand how (and almost as important) WHEN to use them. Maybe I can use all three to accomplish the same task – but should I, and how?
The picture attached is how far I have gotten with 1 led working just fine with the concept.
Thanks community!
Interrupts decisions & inputs with a push button
Moderator: Benj
-
- Posts: 11
- Joined: Sun May 04, 2014 12:07 am
- Been thanked: 1 time
- Contact:
Interrupts decisions & inputs with a push button
- Attachments
-
- so far.PNG
- (49.08 KiB) Downloaded 2330 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Interrupts decisions & inputs with a push button
Hello,
How's this?
We have an endless loop. Inside the loop we wait for the switch to go high. Once the switch has gone high we output our count value to the LED port. The PointGraph function basically outputs (1 << count) or 1 left shifted by the index.
We then wait for the switch to be released. Once the switch is released we increment the counter and check to see if we are at the last LED before resetting to 0.
For more than 8 LEDs you would need multiple LED array components and to switch between them using a decision based on the count value.
How's this?
We have an endless loop. Inside the loop we wait for the switch to go high. Once the switch has gone high we output our count value to the LED port. The PointGraph function basically outputs (1 << count) or 1 left shifted by the index.
We then wait for the switch to be released. Once the switch is released we increment the counter and check to see if we are at the last LED before resetting to 0.
For more than 8 LEDs you would need multiple LED array components and to switch between them using a decision based on the count value.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 11
- Joined: Sun May 04, 2014 12:07 am
- Been thanked: 1 time
- Contact:
Re: Interrupts decisions & inputs with a push button
Wow that's EXACTLY the outcome I was looking for and I didn't know what a point graph was let alone that it was even an option. I am extremely grateful for the solution don't get me wrong, but I still want to understand better how to do this exact same outcome without a led array and point graphs - say I wanted 15 leds, all manually placed with no array or maybe 2 arrays; 1 of 8 the other of 7 (not sure if it matters) but can I use interrupts for this - better yet SHOULD I, if I can?
again thank you sooo much!!
again thank you sooo much!!
-
- Posts: 11
- Joined: Sun May 04, 2014 12:07 am
- Been thanked: 1 time
- Contact:
Re: Interrupts decisions & inputs with a push button
OK that's also really weird. It works perfectly in the simulator but when I program it to the chip the leds are completely backwards? all leds are on to begin with and as the button is pressed the led turns off. HUH!?@
-
- Posts: 11
- Joined: Sun May 04, 2014 12:07 am
- Been thanked: 1 time
- Contact:
Re: Interrupts decisions & inputs with a push button
Never mind, fixed! - I'm an idiot, and wired the leds backwards on the board!
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Interrupts decisions & inputs with a push button
Hello,
Wiring LEDs backwards is easy done. Glad you sorted it.
Here is a version using ports instead of the LED array components. It should show you how to add more LEDs and work without relying on the functions from the LED array.
1 << count basically does this.
when count = 0
0b00000001 << 0 = 0b00000001
when count = 1
0b00000001 << 1 = 0b00000010
when count = 2
0b00000001 << 2 = 0b00000100
etc.
Interrupts are very useful when you need to make sure you don't miss something or need to react quickly to an event or need to time something. As your program is currently very simple with no delays etc we don't really need to use interrupts.
An example of when to use an interrupt would be if you wanted the LEDs to stay on for a period of time after you release the switch. If you simply used a delay you might miss switch presses while in the delay so you could either use an interrupt on the switch press (INT or IOC) or you could use a timer interrupt instead of a delay.
Wiring LEDs backwards is easy done. Glad you sorted it.
Here is a version using ports instead of the LED array components. It should show you how to add more LEDs and work without relying on the functions from the LED array.
1 << count basically does this.
when count = 0
0b00000001 << 0 = 0b00000001
when count = 1
0b00000001 << 1 = 0b00000010
when count = 2
0b00000001 << 2 = 0b00000100
etc.
Interrupts are very useful when you need to make sure you don't miss something or need to react quickly to an event or need to time something. As your program is currently very simple with no delays etc we don't really need to use interrupts.
An example of when to use an interrupt would be if you wanted the LEDs to stay on for a period of time after you release the switch. If you simply used a delay you might miss switch presses while in the delay so you could either use an interrupt on the switch press (INT or IOC) or you could use a timer interrupt instead of a delay.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
-
- Posts: 8
- Joined: Wed Jan 20, 2021 8:42 pm
- Contact:
Re: Interrupts decisions & inputs with a push button
Hello, did you solved your problem? If yes can you show me some guide? Mine near same like you but just difference situation.f234fr32r4 wrote: ↑Mon Jan 18, 2016 7:02 pmNever mind, fixed! - I'm an idiot, and wired the leds backwards on the board!