12 April, 2019

Experimenting blinking an LED with Gobot and Raspberry Pi

In the post 'Playing with Gobot on a Raspberry Pi', I got a Go program running on a Raspberry Pi. In this post, I am going to continue experimenting with different ways to use the Gobot framework to flash a LED.

Experiment - blink multiple sequences

In this experiment, I want to flash the LED three times rapidly then blink the LED continuously.

I created two functions. The first function flashes a LED rapidly three times. To accomplish this, I used a for loop and the sleep function. The second function flashed the LED every second. The 'work' variable calls the two new functions.

Here is the code

Experiment - changing brightness

Let's try something a little bit more complex. I want to be able to control the brightness of the LED. The first thing I did grab the example code (api_led_brightness) from Gobot. My first attempt at running the code failed. The code compiled and seems to run but the LED would not change brightness. It took a bit of head scratching before I remembered the Gobot documentation said something about PWM.

The Gobot documentation references pi-blaster. I found that I needed to setup pi-blaster to get the PWM working.

Once I got pi-blaster running on the Raspberry Pi, the example code from Gobot worked. I did encounter a minor weirdness. When I exit the running program, the LED goes to full brightness.

Resources



No comments:

Challenging myself to learn something new

I have recently set a big challenge for myself. I want to know about Machine Learning . To add to the challenge, I am trying out usin...