LedBlink | Arduino full stack tutorial
kandi X-RAY | LedBlink Summary
kandi X-RAY | LedBlink Summary
Arduino full stack tutorial.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of LedBlink
LedBlink Key Features
LedBlink Examples and Code Snippets
Community Discussions
Trending Discussions on LedBlink
QUESTION
I was writing a simple program for the led blink, the program was working fine with GPIO_NUM_2
but when the led pin num is changed to GPIO_NUM_2
the program started behave oddly, and I don't know why that is happening. Please explain what mistake I am making.
ANSWER
Answered 2020-Nov-04 at 08:19GPIOs 6 to 11 are usually connected to the SPI flash memory. If you try to use them for something else, the MCU can no longer read the program it is executing and will fail.
QUESTION
I come here after after trying in all directions to come out of this problem without any results, unfortunately.
What I have in mind:
I need a class, named Led, that in the constructor simply accept a GPIO pin and offer method for:
- Light On
- Light Off
- Blinking
What I do:
I have build this class in this way:
...ANSWER
Answered 2017-Oct-26 at 16:57You are creating lots of threads because your blink()
creates a new thread every time it is called and the old one isn't stopped.
I suppose there are a couple of options with the thread:
Create the thread just once - for example in
__init__()
- and it runs continuously on the blinking time intervals (i.e. sleeping most of the time) reading an instance variable and setting the LED correspondingly. To change the led state, theblink()
,on()
andoff()
control the led by setting this instance variable to on/off/blinking.In the blink routine, if the thread is already running either don't create a new thread, or stop the old thread (and wait for it to finish) and then start a new one.
Things you will have to handle are that you want the behaviour to be that:
- If the led is off then the led turns on as soon as
on()
orblink()
is called - If the led is blinking and
blink()
is called again the blinking on/off sequence is not disturbed - If blinking and
off()
is called I would want the on-cycle if it has started to run to completion, i.e. the led should not be turned off immediately because that might be a very short flash which would look odd.
The catch with creating a new thread is waiting for the old one to finish, and it just feels simplest to create the thread just once in __init__()
and have it running continuously. When the led is on or off, the time period is shortened (to value FAST_CYCLE
) so that when the led is turned off or on it reacts quickly because the sleep()
is for a short time.
Some other points about your code:
- I don't think you need to make your class inherit from
Thread
- you are creating a new thread in thepin=...
line. - If you add comments as you write the code, usually makes it easier to understand what is going on when reading the code.
- If you keep a reference to the thread (i.e.
self.pin = threading.Thread
notpin = threading.Thread
) then in thereset()
you can usejoin()
to make sure it has exited before you continue - As the blink time periods can change and the thread has to use the latest values, use self to read them every time rather than pass them as arguments to the
__blink_pin()
routine, and if doing that you might as well use self to get the pin_stop semaphore too.
Something like this (untested):
QUESTION
I am making a simple Led program that will be turned into a library for my project. I have created four methods that will allow you to A) Setup as many Led pins as you want and make them as Outputs. B) Flash the Led lights at a customized time. C) Turn On Leds. D) Turn Off Leds. Everything is working if i just run the methods in the void loop(). For example:
...ANSWER
Answered 2017-Feb-25 at 11:04The serial monitor sends symbols encoded in the ASCII format.
e.g. when you enter 0
, Serial.read()
returns 48
, which is the ASCII code for digit 0
. Since the value 48
is not listed in the following cases, the default branch is taken:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install LedBlink
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page