Unable to find a program to control led using conditional statements to switch the led on/off

can anyone help me with a code to switch the led on/off, instead of editing the code again and again
is there any way we can include both the options in the same code using conditional statements?

Hi @vineeshabalani,

Can you share your current code?

You can use the below code, In the below code you have one button to switch on the LED and another button to switch of the LED.

  <!-- In following  line will load the boltCommands.js files from Bolt cloud.-->
  <script type="text/javascript" src="https://cloud.boltiot.com/static/js/boltCommands.js">

  <script type="text/javascript">
    // The following line will set the api key and device name. It will be auto-initialized by Bolt cloud.

  <!-- In below line, We are calling the digitalWrite function from  boltCommands.js file to switch on the LED. -->
  <button onclick="digitalWrite(0, 'HIGH');">ON</button>

  <!-- In below line, we are calling the digitalWrite function from boltCommands.js file to switch off the LED. -->
  <button onclick="digitalWrite(0, 'LOW');">OFF</button>


Do let me know in case you need any other information.

Thank you so much for this code but I was trying to find a code in python. The for controlling led from ubuntu.

Hi @vineeshabalani
You can try this code:

import conf
from boltiot import Bolt
mybolt = Bolt(conf.API_KEY,conf.DEVICE_ID)
while True :
    print("Select Option :")
    led = int(input("1) LED on Press 1\t 2) LED off Press 0 \n"))
    if led == 1:
        response = mybolt.digitalWrite('0',"HIGH")
        print (response)
    elif led == 0:
        response = mybolt.digitalWrite('0',"LOW")
        print (response)
    else :
        print("Select Valid Option")
    br = input("Do you want to continue (y/n) : ")
    if (br == "N") or (br == "n") :
print("Thank You")