A beginner needs help with the last function of the code - Raspberry Pi Forums


i building box opens every 5 kilo loose in weight. have button on box , screen. every button press 1 hekto subtracted 5 kilo on screen. need happens when reaches 0. when screen reaches 0 want servo open , when press 1 more time , screen reaches -0.1 want servo close again , number restore 5 again can start over. have tried write function in several different ways, have not got work yet, started programing , bit lost now. when value reaches 0 continue -0.1, -0.2 , on, nothing happens.

how should write last part?

code: select all

# -*- coding: utf-8 -*-  import rpi.gpio gpio import time adafruit_led_backpack import sevensegment  display = sevensegment.sevensegment() display.begin() colon = false  gpio.setmode(gpio.bcm)  gpio.setup(17, gpio.in, pull_up_down=gpio.pud_up) #knapp  gpio.setup(18,gpio.out) #servo gpio.setup(5,gpio.out) gpio.setup(6,gpio.out)   p = gpio.pwm(18,50)  p.start(12)   hekto = 4.9  gpio.output(6, true)  numbers = [5.0]  input_state = gpio.input(17)  print('press ctrl-c quit.') while true:     in numbers:         display.clear()         display.print_float(i, decimal_digits=2)         display.set_colon(colon)         display.write_display()         time.sleep(0.2)         input_state = gpio.input(17)         if input_state == false:             numbers[0] = hekto             hekto -= 0.1             print('knapp')                      if numbers[0] == 0.0:       #open servo                 p.changedutycycle(12.5)              if numbers[0] == -0.1:      #close servo reset number                  p.changedutycycle(3.5)                 numbers[0] = 5.0           

you're setting numbers[0] hekto not resetting hekto when set numbers[0] 5.0. don't understand why have list of 1 value , why duplicate in hekto. there doesn't seem functionality append numbers not clear why list , why loop. kind of pulse counting?


raspberrypi



Comments