Dear Sirs,
Is it not strange that I have to write twice in my code:
import grove pi
from grovepi import *
and
import time
from time import sleep
I connected a microphone to A0 on my Grovepi and a ledbar to D5.
Thereafter I wrote te next code: (see below)
What do you think about it?
can you give me your profesional opinion and give me some points to improve the code?
Yours sincerely,
Marc stevens.
import grovepi
from grovepi import *
import time
from time import sleep
ledbar=5
while True:
volume=analogRead(0)
vol=volume/10
if vol>100:
grovepi.ledBar_setLevel(ledbar, 10)
sleep(.1)
if vol>90:
grovepi.ledBar_setLevel(ledbar, 9)
sleep(.1)
if vol>80:
grovepi.ledBar_setLevel(ledbar, 8)
sleep(.1)
if vol>70:
grovepi.ledBar_setLevel(ledbar, 7)
sleep(.1)
if vol>60:
grovepi.ledBar_setLevel(ledbar, 6)
sleep(.01)
if vol>50:
grovepi.ledBar_setLevel(ledbar, 5)
sleep(.1)
if vol>40:
grovepi.ledBar_setLevel(ledbar, 4)
sleep(.1)
if vol>30:
grovepi.ledBar_setLevel(ledbar, 3)
sleep(.1)
if vol>20:
grovepi.ledBar_setLevel(ledbar, 2)
sleep(.1)
elif vol>10:
grovepi.ledBar_setLevel(ledbar, 1)
sleep(.1)
else:
grovepi.ledBar_setLevel(ledbar, 0)
sleep(.1)