I'm almost done with a project but when I give a value that is to high. I barely hear de buzzer playing because it only plays for a sec. Does someone know how to play the buzzer sound longer?
import pycom
import machine
import time
from machine import Pin
import socket
from network import LoRa
import binascii
import array
from machine import PWM
############### Weightsensor ###############
def main():
while True:
adc = machine.ADC() # create an ADC object
apin = adc.channel(pin='P16') # create an analog pin on P16
val = apin() # read an analog value
if val < 20:
print(val)
print("Weight is good")
binaryString = bin(val)
print(binaryString)
time.sleep(5)
if val > 20:
print(val)
print("Weight is to high")
binaryString = bin(val)
print(binaryString)
# 50% duty cycle at 38kHz.
pwm = PWM(3, frequency=78000) # use PWM timer 0, with a frequency of 5KHz
# create pwm channel on pin P12 with a duty cycle of 50%
pwm_c = pwm.channel(0, pin='P20', duty_cycle=1.0)
pwm_c.duty_cycle(0.3) # change the duty cycle to 30%
time.sleep(5)
if __name__ == "__main__":
main()
The buzzer plays in the second "if" statement.
Can someone help me out please?
Kind regards