Created
April 16, 2017 04:08
-
-
Save Ryomasao/2ead7d3f720fd12f7be332eca99df0ba to your computer and use it in GitHub Desktop.
ステッピングモーターを動かす
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wiringpi as pi | |
import time | |
#割り当てるPIN番号とステッピングモータの線の関係 | |
BLUE_A1 = 4 | |
WHITE_A2 = 17 | |
YELLOW_B1 = 27 | |
RED_B2 = 22 | |
#信号をおくる間隔(秒) | |
SPEED = 0.1 | |
#wirigpiの初期化 | |
pi.wiringPiSetupGpio() | |
#PINの割り当て | |
pi.pinMode( BLUE_A1, pi.OUTPUT ) | |
pi.pinMode( WHITE_A2, pi.OUTPUT ) | |
pi.pinMode( YELLOW_B1, pi.OUTPUT ) | |
pi.pinMode( RED_B2, pi.OUTPUT ) | |
while True: | |
#2相励磁方式なるパターン | |
#青、赤に電圧をかけ、他はかけない→赤、白に電圧をかけ他はかけない、みたいな感じで | |
#繰り返していく。 | |
#一回のパターンで、7.5度ずつ回転する。 | |
pi.digitalWrite( BLUE_A1,1) | |
pi.digitalWrite( RED_B2,1) | |
pi.digitalWrite( WHITE_A2,0) | |
pi.digitalWrite( YELLOW_B1,0) | |
time.sleep( SPEED ) | |
pi.digitalWrite( BLUE_A1,0) | |
pi.digitalWrite( RED_B2,1) | |
pi.digitalWrite( WHITE_A2,1) | |
pi.digitalWrite( YELLOW_B1,0) | |
time.sleep( SPEED ) | |
pi.digitalWrite( BLUE_A1,0) | |
pi.digitalWrite( RED_B2,0) | |
pi.digitalWrite( WHITE_A2,1) | |
pi.digitalWrite( YELLOW_B1,1) | |
time.sleep( SPEED ) | |
pi.digitalWrite( BLUE_A1,1) | |
pi.digitalWrite( RED_B2,0) | |
pi.digitalWrite( WHITE_A2,0) | |
pi.digitalWrite( YELLOW_B1,1) | |
time.sleep( SPEED ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment