Friday 5 December 2014

Program for Led Glowing(ON OR OFF)

STEP 1:

Open LX-Terminal.

Create a file with .py extension

Ex: nano led.py

Nano is a type of editor used to write the code in that file named led.

Type the following code in that file by insert key or by typing letter I on keyboard.

Program:

To turn on LED’S

#! /usr/bin/python
Import RPi.GPIO as GPIO          //To import the RPi.GPIO module
GPIO.setmode (GPIO.BCM)       //Now set the mode to represent the numbering scheme you prefer.
GPIO.cleanup ()                            //Return all channels you have used back to inputs.
GPIO.setwarnings (False)            //Turn off warnings that are annoying.
GPIO.setup (17, GPIO.OUT)      //You need to set up every channel you are using as input/output.                                                              This one is an output
GPIO.setup (27, GPIO.OUT)      //Setup again but this time pin 27.
Print “Lights on”                          //To turn LEDs ON
GPIO.output (17, GPIO.HIGH)  // led on purpose
GPIO.output (27, GPIO.HIGH) //led on purpose

Save the file by typing  :wq and then press enter

To check output:Type python led.py


Output 1:

To turn off LED’S

#! /usr/bin/python
Import RPi.GPIO as GPIO           //To import the RPi.GPIO module
GPIO.setmode (GPIO.BCM)       //Now set the mode to represent the numbering scheme you prefer.
GPIO.cleanup ()                            //Return all channels you have used back to inputs.
GPIO.setwarnings (False)            //Turn off warnings that are annoying.
GPIO.setup (17, GPIO.OUT)      //configuring 17th pin as output
GPIO.setup (27, GPIO.OUT)      // configuring 27th pin as output
Print “Lights on”                          //To turn LEDs ON
GPIO.output (17, GPIO.LOW)   // led off purpose
GPIO.output (27, GPIO.LOW)   //led off purpose

To check output:Type python led.py

Output 2:


0 comments:

Post a Comment