De olho nas novidades!
Desde a última semana estão chegando novos itens para a oficina.
- Pi Câmera
- Relés
- Joystick
- Motor de passo
- Display 16x2
- Multímetro bacanudo (o anterior foi pro saco quando troquei a bateria)
Mas ainda faltam chegar algumas coisas importantes, como resistores de diferentes valores, e que fazem muita falta, além de dois PICs 16F84a.
Além destes, chegaram os irmãos mais novos do Raspberry Pi B:
- 4x Raspberrys Pi B+
- 1x Raspberry Pi A+
Boa parte dos equipamentos já foram testados e aguardam a vez para figurarem nos novos projetos (chega de LEDs, certo?). Também montei um cluster com os Raspis, e o post sobre a experiência está quase pronto (faltam os testes de desempenho).
Não suma, novos projetos virão, mas, pra não passar em branco, segue o código de um jogo de luzes utilizando Raspberry Pi, LEDs e resistores de 300ohms.
Arquivo ledshow.py
from Pin import Pin
import time
leds = [Pin(17), Pin(27), Pin(22), Pin(18), Pin(23), Pin(24), Pin(25), Pin(8)]
def a2h(inter):
for i in range(0, 8):
leds[i].on()
time.sleep(inter)
leds[i].off()
def h2a(inter):
i = 7
while(i >= 0):
leds[i].on()
time.sleep(inter)
leds[i].off()
i -= 1
def b2m(inter):
i = 0
j = 7
while i <= 3:
leds[i].on()
leds[j].on()
time.sleep(inter)
leds[i].off()
leds[j].off()
i += 1
j -= 1
def m2b(inter):
i = 3
j = 4
while i >= 0:
leds[i].on()
leds[j].on()
time.sleep(inter)
leds[i].off()
leds[j].off()
i -= 1
j += 1
for i in range(0, 10):
a2h(0.10)
h2a(0.10)
b2m(0.10)
m2b(0.10)
b2m(0.10)
m2b(0.10)
Classe Pin.py (a classe está só no início, ou seja, muita coisa precisa melhorar):
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
class Pin:
number = 0
anode = False
pwmod = False
def __init__(self, number, mode = GPIO.OUT):
self.number = number
self.pin = GPIO
self.pin.setup(number, mode)
def inverter(self):
if self.anode:
self.anode = False
else:
self.anode = True
def on(self):
self.pin.output(self.number, (self.anode != True))
def off(self):
self.pin.output(self.number, (self.anode != False))
if self.pwmod != False:
self.pwmod.start(100)
self.pwmod.stop()
def setPWM(self, hertz):
self.pwmod = self.pin.PWM(self.number, hertz)
self.pwmod.start(0)
def setCycle(self, cycle):
self.pwmod.ChangeDutyCycle(cycle)
Demo:
- Pi Câmera
- Relés
- Joystick
- Motor de passo
- Display 16x2
- Multímetro bacanudo (o anterior foi pro saco quando troquei a bateria)
Mas ainda faltam chegar algumas coisas importantes, como resistores de diferentes valores, e que fazem muita falta, além de dois PICs 16F84a.
Além destes, chegaram os irmãos mais novos do Raspberry Pi B:
- 4x Raspberrys Pi B+
- 1x Raspberry Pi A+
Boa parte dos equipamentos já foram testados e aguardam a vez para figurarem nos novos projetos (chega de LEDs, certo?). Também montei um cluster com os Raspis, e o post sobre a experiência está quase pronto (faltam os testes de desempenho).
Não suma, novos projetos virão, mas, pra não passar em branco, segue o código de um jogo de luzes utilizando Raspberry Pi, LEDs e resistores de 300ohms.
Arquivo ledshow.py
from Pin import Pin
import time
leds = [Pin(17), Pin(27), Pin(22), Pin(18), Pin(23), Pin(24), Pin(25), Pin(8)]
def a2h(inter):
for i in range(0, 8):
leds[i].on()
time.sleep(inter)
leds[i].off()
def h2a(inter):
i = 7
while(i >= 0):
leds[i].on()
time.sleep(inter)
leds[i].off()
i -= 1
def b2m(inter):
i = 0
j = 7
while i <= 3:
leds[i].on()
leds[j].on()
time.sleep(inter)
leds[i].off()
leds[j].off()
i += 1
j -= 1
def m2b(inter):
i = 3
j = 4
while i >= 0:
leds[i].on()
leds[j].on()
time.sleep(inter)
leds[i].off()
leds[j].off()
i -= 1
j += 1
for i in range(0, 10):
a2h(0.10)
h2a(0.10)
b2m(0.10)
m2b(0.10)
b2m(0.10)
m2b(0.10)
Classe Pin.py (a classe está só no início, ou seja, muita coisa precisa melhorar):
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
class Pin:
number = 0
anode = False
pwmod = False
def __init__(self, number, mode = GPIO.OUT):
self.number = number
self.pin = GPIO
self.pin.setup(number, mode)
def inverter(self):
if self.anode:
self.anode = False
else:
self.anode = True
def on(self):
self.pin.output(self.number, (self.anode != True))
def off(self):
self.pin.output(self.number, (self.anode != False))
if self.pwmod != False:
self.pwmod.start(100)
self.pwmod.stop()
def setPWM(self, hertz):
self.pwmod = self.pin.PWM(self.number, hertz)
self.pwmod.start(0)
def setCycle(self, cycle):
self.pwmod.ChangeDutyCycle(cycle)
Demo:
Comentários
Postar um comentário