My name is Ryosuke Kamei and I am an IT consultant based on the idea of "gentle IT"! Currently, in my work, I am doing upstream processes focusing on requirements analysis and requirements definition, but I also write programs! As part of our friendly IT activities, we will introduce "Raspberry Pi 3" (commonly known as Raspberry Pi), which has the philosophy of "providing inexpensive PCs that can be programmed for education"!
This time, the LED is lit by switch control! [Razpai Magazine-August 2016 Special Feature 1 Basic Pattern of Electronic Work 12 ① Infinite Loop and Conditional Branching](https://www.amazon.co.jp/%E3%83%A9%E3%82%BA % E3% 83% 91% E3% 82% A4% E3% 83% 9E% E3% 82% AC% E3% 82% B8% E3% 83% B3-2016% E5% B9% B48% E6% 9C% 88 % E5% 8F% B7-% E6% 97% A5% E7% B5% 8CBP% E3% 83% 91% E3% 82% BD% E3% 82% B3% E3% 83% B3% E3% 83% 99% E3% 82% B9% E3% 83% 88% E3% 83% A0% E3% 83% 83% E3% 82% AF-% E6% 97% A5% E7% B5% 8CLinux / dp / 4822237710 / ref = as_li_ss_tl ? ie = UTF8 & qid = 1471057119 & sr = 8-4 & keywords =% E3% 83% A9% E3% 82% BA% E3% 83% 91% E3% 82% A4 & linkCode = ll1 & tag = sr2smail-22 & linkId = c42c3f78bd8af3af1414020a400090fe)
[Razpai Magazine-August 2016 Special Feature 1 Basic Pattern of Electronic Work 12 ① Infinite Loop and Conditional Branching](https://www.amazon.co.jp/%E3%83%A9%E3%82%BA % E3% 83% 91% E3% 82% A4% E3% 83% 9E% E3% 82% AC% E3% 82% B8% E3% 83% B3-2016% E5% B9% B48% E6% 9C% 88 % E5% 8F% B7-% E6% 97% A5% E7% B5% 8CBP% E3% 83% 91% E3% 82% BD% E3% 82% B3% E3% 83% B3% E3% 83% 99% E3% 82% B9% E3% 83% 88% E3% 83% A0% E3% 83% 83% E3% 82% AF-% E6% 97% A5% E7% B5% 8CLinux / dp / 4822237710 / ref = as_li_ss_tl ? ie = UTF8 & qid = 1471057119 & sr = 8-4 & keywords =% E3% 83% A9% E3% 82% BA% E3% 83% 91% E3% 82% A4 & linkCode = ll1 & tag = sr2smail-22 & linkId = c42c3f78bd8af3af1414020a400090fe)
If you get an image like this, referring to the picture of the circuit
Text version From the Raspberry Pi side
--Raspberry Pi Pin 1 (3.3V) --Left side of slide switch --Raspberry Pi 11th pin (GPIO17) --Slide switch center --Raspberry Pi 16th pin (GPIO23) --LED 1st plus side --Raspberry Pi 18th pin (GPIO24) --LED 2nd plus side --Raspberry Pi 6th pin (GND) --Slide switch right side --Raspberry Pi 6th pin (GND) --Resistance (100Ω) --LED 1st minus side --Raspberry Pi 6th pin (GND) --Resistance (100Ω) --LED 2nd minus side
[Razpai Magazine-August 2016 Special Feature 1 Basic Pattern of Electronic Work 12 ① Infinite Loop and Conditional Branching](https://www.amazon.co.jp/%E3%83%A9%E3%82%BA % E3% 83% 91% E3% 82% A4% E3% 83% 9E% E3% 82% AC% E3% 82% B8% E3% 83% B3-2016% E5% B9% B48% E6% 9C% 88 % E5% 8F% B7-% E6% 97% A5% E7% B5% 8CBP% E3% 83% 91% E3% 82% BD% E3% 82% B3% E3% 83% B3% E3% 83% 99% E3% 82% B9% E3% 83% 88% E3% 83% A0% E3% 83% 83% E3% 82% AF-% E6% 97% A5% E7% B5% 8CLinux / dp / 4822237710 / ref = as_li_ss_tl ? ie = UTF8 & qid = 1471057119 & sr = 8-4 & keywords =% E3% 83% A9% E3% 82% BA% E3% 83% 91% E3% 82% A4 & linkCode = ll1 & tag = sr2smail-22 & linkId = c42c3f78bd8af3af1414020a400090fe)
The source is uploaded to GitHub, so please use it as you like.
Clone with git
$ git clone https://github.com/RyosukeKamei/raspberrypi3.git
switch_led.py
#Library to control GPIO
import wiringpi
#Timer library
import time
#Get arguments
import sys
#GPIO definition
led1_pin = 23
led2_pin = 24
switch_pin = 17
#Get the interval to shine from the argument
param = sys.argv
set_interval = int(param[1])
#GPIO initialization
wiringpi.wiringPiSetupGpio()
wiringpi.pinMode( led1_pin, 1 )
wiringpi.pinMode( led2_pin, 1 )
wiringpi.pinMode( switch_pin, 0 )
#Which LED is on
led = 0
#This circuit is permanent, so repeat until you stop
while True:
#Turn off the LED
wiringpi.digitalWrite( led1_pin, 0 )
wiringpi.digitalWrite( led2_pin, 0 )
#Detect slide switch
while ( wiringpi.digitalRead(switch_pin) == 1 ):
#Switch on
print("Switch on")
if ( led == 0 ):
#Make LED1 shine
wiringpi.digitalWrite( led1_pin, 1 )
wiringpi.digitalWrite( led2_pin, 0 )
led = 1
print("LED1")
else:
#Make LED2 shine
wiringpi.digitalWrite( led1_pin, 0 )
wiringpi.digitalWrite( led2_pin, 1 )
led = 0
print("LED2")
#Wait for the number of seconds specified by the argument
print(set_interval, "Wait for seconds")
time.sleep(set_interval)
I recorded the video of how it is moving.
LED switching every 3 seconds
$ sudo python3 switch_led.py 3
Install Raspberry Pi 3 → Wireless LAN → Japanese input / output → Operate from Mac
Install Docker on RaspberryPi3 Build a Python + bottle + MySQL environment with Docker on RaspberryPi3![Easy construction] Build a Python + bottle + MySQL environment with Docker on RaspberryPi3![Trial and error]
Make an air conditioner integrated PC "airpi" with Raspberry Pi 3!
Programming with Node-RED programming with Raspberry Pi 3 and programming normally Light the LED with python on Raspberry Pi 3 (Hello World) Detect switch status on Raspberry Pi 3 Run a servo motor using python on Raspberry Pi 3 Control the motor with a motor driver using python on Raspberry Pi 3! Detect slide switch using python on Raspberry Pi 3! Detect magnet switch using python on Raspberry Pi 3! Detect temperature using python on Raspberry Pi 3! Sound the buzzer using python on Raspberry Pi 3! Detect analog signals with A / D converter using python on Raspberry Pi 3! Detect "brightness" using python on Raspberry Pi 3! Detect "temperature (using A / D converter)" using python on Raspberry Pi 3! Output to "7-segment LED" using python on Raspberry Pi 3! Use python on Raspberry Pi 3 to light the LED with switch control!
Coding rules "Let's write gentle code" (FuelPHP) Naming convention "Friendly to yourself, team-friendly, and unseen members after 3 months"
PHP environment + Eclipse is linked to Apache using Docker Building FuelPHP development environment using Docker Create CRUD skeleton using initial settings of FuelPHP development environment using Docker and scaffold FuelPHP database migration
Recommended Posts