add smooth blinky example
This commit is contained in:
@@ -233,6 +233,8 @@ Code to turn the fan on and off with a 2 second delay:
|
||||
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Binary LED Counter
|
||||
|
||||
This example again uses 5 LEDS to visualize a 5 bit binary counter. Mask commands are used to set the LEDS simultaneously.
|
||||
@@ -257,6 +259,34 @@ if counter is `11001`, `counter<<11` will be `1100100000000000`.
|
||||
|
||||
---
|
||||
|
||||
## SmoothBlinky
|
||||
|
||||
This example demonstrates how brightness of an LED can be controlled by modulating the output using the time delay
|
||||
|
||||
```c
|
||||
const uint LEDPin = 14;
|
||||
gpio_init(LEDPin);
|
||||
gpio_set_dir(LEDPin, GPIO_OUT);
|
||||
gpio_set_drive_strength(LEDPin, GPIO_DRIVE_STRENGTH_2MA);
|
||||
int onDelay=0;
|
||||
int totalDelay=10;
|
||||
while (true)
|
||||
{
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
gpio_put(LEDPin, true);
|
||||
sleep_ms(onDelay);
|
||||
gpio_put(LEDPin, false);
|
||||
sleep_ms(totalDelay - onDelay);
|
||||
}
|
||||
onDelay = (onDelay+1) % totalDelay;
|
||||
}
|
||||
```
|
||||
|
||||
`onDelay` is maintained such that total time for each iteration remains constant, equal to `totalDelay`. This above code will make the LED look like the brightness changes.
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
Below are the API calls used in this document:
|
||||
@@ -282,3 +312,5 @@ Below are the API calls used in this document:
|
||||
| - | - | - |
|
||||
| `sleep_ms` | TIME | Pauses the program for given number of milli-seconds when called |
|
||||
| `stdio_init_all` | -- | Initializes stuff |
|
||||
|
||||
add fading led example by changing the amount of times the led blinks in a given cycle.
|
||||
|
||||
Reference in New Issue
Block a user