From 560076fb264dc79f50034a34643e4c9418c920f6 Mon Sep 17 00:00:00 2001 From: kunal768 <33108756+kunal768@users.noreply.github.com> Date: Mon, 29 Oct 2018 10:14:27 +0530 Subject: [PATCH] Created a file for "Basics of Raspberry Pi Stuffs" (#20150) * Created a file for "Basics of Raspberry Pi Stuffs" The code contains two parts: First part is simply blinking led (Blink time can be set by time.sleep(x) x for the number of seconds) Second part is for pwm control for led brightness * Update RaspberryPiBasics.py * reformatted two 2 space indention with title corr. --- .../python/raspberry-pi-basics/index.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 guide/english/python/raspberry-pi-basics/index.md diff --git a/guide/english/python/raspberry-pi-basics/index.md b/guide/english/python/raspberry-pi-basics/index.md new file mode 100644 index 0000000000..22ac063f06 --- /dev/null +++ b/guide/english/python/raspberry-pi-basics/index.md @@ -0,0 +1,38 @@ +--- +title: Rasberry PI Basics +--- + +## Rasberry PI Basics Example +```python +## CODE THAT MAKES AN LED GLOW FOR 2 SECONDS +import time +import RPi.GPIO as GPIO +while True: + GPIO.output(2, GPIO.HIGH + time.sleep(1) + GPIO.output(2, GPIO.LOW) + time.sleep(1) + +## CODE FOR PWM CONTROL OF LED BRIGHNTESS +import RPi.GPIO as GPIO from time +import sleep led_pin = 2 + +GPIO.setmode(GPIO.BCM) +GPIO.setup(led_pin, GPIO.OUT) + +pwm = GPIO.PWM(led_pin, 100) +pwm.start(0) + +try: + while True: + for x in range(100): + pwm.ChangeDutyCycle(x) + sleep(0.01) + for x in range(100, 0, -1): + pwm.ChangeDutyCycle(x) + sleep(0.01) + +except KeyboardInterrupt: + pwm.stop() + GPIO.cleanup() +```