Python code to turn off the buzzer after 5 sec

If the current price is greater than the selling price, the program should trigger the Bolt Cloud API to switch on the buzzer connected to the Bolt module for 5 seconds and then switches it off after 5 seconds

while True:

        bitcoin_price = get_bitcoin_price()
        print('The current bitcoin value in USD is ', bitcoin_price)

        if bitcoin_price > selling_price:
                print('The current price is  greater than selling price')
                print('current price: ' + str(bitcoin_price) + 'and selling price: ' + str(selling_price))
                response = mybolt.digitalWrite('0','HIGH')
                data = json.loads(response)
                print(data)
                time.sleep(5)
                response = mybolt.digitalWrite('0','LOW')
                data = json.loads(response)
                print(data)
        time.sleep(30)
1 Like

Hi @hussainbadri5253

You can check below sample code

while True:
# Step 1: get bitcoin price
[usd,ind] = get_bitcoin_price()
print(β€œThe current bitcoin value in $ is:”, usd)

# Step 2: send signal to buzzer
if usd>selling_price:
    print(alertprice.isOnline())
    response=alertprice.digitalWrite(0,'HIGH')
    print(response)
     time.sleep(5)
    response=alertprice.digitalWrite(0,'LOW')
    send_telemsg('Bitcoin price aleart\n USD: '+str(usd)+'\nIND: '+str(ind))
time.sleep(30) 

P.S. Update the URL in get_bitcoin_price() function to something like this URL = β€œhttps://min-api.cryptocompare.com/data/price?fsym=BTC&tsyms=USD,IND”