this is the code am writing to turn on the switch on and off but here unable to get the print statement on when the value is 1 everytime only the off statement is getting print at any situation
# !/usr/bin/python
import RPi.GPIO as GPIO
import blynklib
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(2, GPIO.OUT)
auth_token = "Blynk Auth Code Here"
# Initialize Blynk
def write_handler_pin_handler(pin, value):
switch = (format(value[0]))
if switch == 1:
print("On")
else:
print("Off")
try:
while True:
blynk.run()
except KeyboardInterrupt:
print("Quit")
# Reset GPIO settings
GPIO.cleanup()
Emilio
April 3, 2019, 10:22pm
2
Gunner
April 3, 2019, 10:22pm
3
@aravind.doha I moved your post into your own topic as the one you put your “me too” into was almost a year old.
I also properly formatted your code as required in the Welcome Topic… please read it thoroughly.
Hey, welcome to Blynk Community.
This is the best place to ask questions, leave feedback and share your ideas.
If this is the first time you hear about Blynk, check out our website www.blynk.cc and come back!
As the community is big (and growing), let’s agree on some basic rules.
Asking for help
Before creating a new topic and asking for help, please check if your question was already answered:
Use forum search function
You may want to check out:
Blynk Documentation
Blynk Wiki
Blynk Exa…
i have rectified issue…i would like to join your team.
frankly speaking am not a experienced developer but like to learn more. if possible let me know if you have any project in python where i can help you
Gunner
April 4, 2019, 7:00am
5
aravind.doha:
i have rectified issue
How?
Aside from the actual Blynk Development team, we are all Blynk users and forum volunteers here, so feel free to assist with any Python related topics that pop up.
its was a typo error instead of if value ==“1” i had mentioned value ==1 if statement
1 Like
rectified and solved code
import RPi.GPIO as GPIO
import blynklib
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(2, GPIO.OUT)
auth_token = "Blynk Auth Code Here"
# Initialize Blynk
def write_handler_pin_handler(pin, value):
switch = (format(value[0]))
if switch == "1":
GPIO.output(2,GPIO.HIGH)
print("On")
else:
GPIO.output(2, GPIO.LOW)
print("Off")
try:
while True:
blynk.run()
except KeyboardInterrupt:
print("Quit")
# Reset GPIO settings
GPIO.cleanup()
will i able to post the code in my GITHUB
Gunner
April 4, 2019, 8:56am
9
Again!! Please properly format all posted code, else it looks bad…
Read the Welcome Topic I posted above!!!
Please find the solved code
import RPi.GPIO as GPIO
import blynklib
import time
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(2, GPIO.OUT)
auth_token = "Blynk Auth Code Here"
# Initialize Blynk
def write_handler_pin_handler(pin, value):
switch = (format(value[0]))
if switch == "1":
GPIO.output(2,GPIO.HIGH)
print("On")
else:
GPIO.output(2, GPIO.LOW)
print("Off")
try:
while True:
blynk.run()
except KeyboardInterrupt:
print("Quit")
# Reset GPIO settings
GPIO.cleanup()
1 Like