Hello
Please help
I am getting the error
current_price not defined
You did not call the function get_bitcoin_price()
, after defining it.
Correction:
def get_bitcoin_price():
.
.
.
current_price=response["USD"]
get_bitcoin_price()
if current_price > selling_price:
.
.
Thanks , it worked
Do the following changes, and check if it gives an appropriate response.
def get_bitcoin_price():
.
.
.
current_price=response["USD"]
return current_price
price = get_bitcoin_price()
if price > selling_price:
.
.
This one worked , thanks
Is it working now? Try with other names for the variable as well. Keep testing the code with small changes.
Yeah it is absolutely working now thank you
Acha can you give me some idea like how to set the buzzer to sound for 5 seconds because I think digitalWrite() does not provide such parameter or can we use tone() for buzzer
Yes, you’re right. digitalWrite does not have that parameter.
To make it sound for 5 seconds, you can use a delay in the python code, to send a digital LOW signal after 5 seconds. So, the buzzer will altogether buzz for 5 seconds.
For delay, you can use time.sleep(5)
in between the 2 digital HIGH and LOW functions.
Let me know if you have any other queries.
As I mentioned, you can simply write,
print("Selling price increased...")
mybolt.digitalWrite("0", "HIGH")
time.sleep(5)
mybolt.digitalWrite("0", "LOW")
DIrectly write current_price = response
, then print(price) to print the response of the bitcoin URL get. If there is no JSON key as “USD”, then that’s what the error is being returned as. Check the URL for errors in that case.
Your mybolt.digitalWrite(‘o’, LOW) has ‘o’ in it. It is supposed to be any of the GPIO pins from 0 - 4. In your case, ‘0’ and not ‘o’.
I stumbled upon this thread from two years ago, and it seems like you were facing an error with your Bitcoin assignment. No worries, I’m here to lend a hand! If you were getting the ““current_price not defined”” error, it means that the variable ““current_price”” is not properly defined in your code. To fix this, make sure you’ve declared and assigned a value to the ““current_price”” variable before using it.