Raspberry pie graphics programming (Python, C + +, scratch, blockpi) part. 1 RGB light interval light


The reptile has been confused recently

For bisher, start with raspberry pie

For the sake of graphic convenience, I first touch scratch graphic programming, although I also know C + + and python.

There are graphic programming in the front, the back is very easy to understand, the first chapter, and strive to write a good raspberry pie and sensor log (dare not say tutorial, too much food).

Embedded first! Pin definition to know

Pin definition diagram:

Pin diagram

C + + uses the wiringpi module, so it uses the pins corresponding to the wiringpi pin; Scratch uses BCM; Python has a setmode() function (both the BCM function and the actual physical pin definition are OK), so I just give the GPIO port the header column of actual physical pins.

This is the wiring method used in this section. There is a breadboard at the bottom. Of course, you can choose to directly insert each DuPont wire into the corresponding pin of raspberry pie.

Wiring diagram:

Wiring diagram

Schematic diagram of corresponding needle without expansion plate:

Physical picture

LED light diagram:


RGB is respectively connected to G17, G18, G27 and GND (that is 0V) (because I use BCM code for this adapter board, the pin number here is the corresponding column number of BCM GPIO).


And then there's circular blinding


(pressCtrl+CStop the calling of sub function, and then click program stop, otherwise the program will close directly and forget to change the duty cycle of all pins to 0.)

import RPi.GPIO as GPIO


#include #define uchar unsigned char


This is a more powerful open source project than scratch3, graphical programming super cool!

Introduction and simple installation

as well as

The author knows a lot about this column

When you finish the graphic programming, there is corresponding Python code generation. I don’t like more about it. The pleasure of building blocks~

Much more powerful than the raspberry pie module in scratch

Directly above:

Graphic programming

Corresponding generated code:

from gpiozero import *
from colorzero import Color
import time

rgbled = None

rgbled = RGBLED(17, 18, 27)
for count in range(10):
  rgbled.color = Color('#ff0000')
  rgbled.color = Color('#009900')
  rgbled.color = Color('#3333ff')