Ryanteck SnowPi – GPIO Zero Guide

Ryanteck SnowPi GPIO Zero Guide.jpgv1561727085
Ryanteck SnowPi GPIO Zero Guide.jpgv1561727085

Pour commencer, assurez-vous que la dernière version de GPIO Zero est installée. Vous pouvez suivre notre guide sur l’installation @ GPIO Zero Install.

Le fonctionnement de SnowPi est en fait très simple et se fait en quelques minutes après la configuration de GPIO Zero à l’aide du guide ci-dessus.

Nous devons d’abord vérifier le nombre de broches GPIO que nous devons utiliser.

snowpi bcm gpio numbers

Nous commencerons par cligner du nez sur le SnowPi qui est GPIO 25.

1) Commencez par ouvrir un éditeur pour Python. Nous utiliserons Idle.

2) Ensuite, cliquez sur Fichier-> Nouveau fichier, cela nous sort de la console interactive / live et dans un fichier où nous pouvons écrire notre code.

3) Maintenant, nous sommes prêts à construire le code. Copiez le code ci-dessous, nous avons commenté les lignes comme guide sur ce que fait chaque ligne.

#First we need to import the LED & Pause class from the GPIO Zero Library

from gpiozero import LED

#We also need the sleep function from the time library

from time import sleep

#Along with pause which we will use later on

from signal import pause

 

#Next we need to create a nose object and assign it a class of an LED.

#This gives us all of the functions available for the LED module in GPIO Zero.

 

nose = LED(25)

 

#Now we're setup we can go through some of the available commands!

 

#Let's begin by turning the nose on!

nose.on()

#And wait 1 second

sleep(1)

#And now turn the nose off,

nose.off()

sleep(1)

 

#We can also toggle the LED instead.

#This means if the LED is already on it will

#turn it off and if it's off turn it on.

 

#Lets try that now with a sleep inbetween

nose.toggle()

sleep(1)

nose.toggle()

sleep(1)

 

#Quite simple, we could put this into a while True: loop and have it blink forever

#However GPIO Zero has a neat little blink function.

 

nose.blink()

 

#And finally if you've got all of your LEDs blinking you can then use

#the pause function to make it run until quit using Ctrl-C

 

pause()

 

#And that's the end of this basic tutorial on blinking an LED on the SnowPi!

#The rest is up to you to decide on patterns you wish to make.