라즈베리파이 DC 모터 제어코드
- 코딩/Raspberry Pi (c)
- 2019. 11. 17.
라즈베리파이 DC 모터 제어코드 1
#include <stdio.h>
#include <wiringPi.h>
const int pinEnable = 12;
const int pinPositive = 4;
const int pinNegative = 25;
int main(void)
{
wiringPiSetupGpio();
pinMode(pinEnable, OUTPUT);
pinMode(pinPositive, OUTPUT);
pinMode(pinNegative, OUTPUT);
while(1)
{
digitalWrite(pinPositive, HIGH);
digitalWrite(pinNegative, LOW);
digitalWrite(pinEnable, HIGH);
delay(2000);
digitalWrite(pinEnable, LOW);
delay(2000);
digitalWrite(pinPositive, LOW);
digitalWrite(pinNegative, HIGH);
digitalWrite(pinEnable, HIGH);
delay(2000);
digitalWrite(pinEnable, LOW);
delay(2000);
}
return 0;
}
라즈베리파이 DC 모터 제어코드 2
#include <stdio.h>
#include <wiringPi.h>
const int pinEnable = 12;
const int pinPositive = 4;
const int pinNegative = 25;
const int aPinSwitch[2] = {6,5};
int main(void)
{
wiringPiSetupGpio();
pinMode(pinEnable, OUTPUT);
pinMode(pinPositive, OUTPUT);
pinMode(pinNegative, OUTPUT);
int i;
for(i=0; i<2; i++)
{
pinMode(aPinSwitch[i], INPUT);
}
while(1)
{
if(digitalRead(aPinSwitch[0]))
{
digitalWrite(pinPositive, HIGH);
digitalWrite(pinNegative, LOW);
digitalWrite(pinEnable, HIGH);
}
else if(digitalRead(aPinSwitch[1]))
{
digitalWrite(pinEnable, LOW);
}
}
return 0;
}
라즈베리파이 DC 모터 제어코드 3
#include <stdio.h>
#include <wiringPi.h>
const int pinEnable = 12;
const int pinPositive = 4;
const int pinNegative = 25;
const int aPinSwitch[2] = {6,5};
void motorSpin(void)
{
digitalWrite(pinEnable, HIGH);
digitalWrite(pinPositive, HIGH);
digitalWrite(pinNegative, LOW);
}
void motorStop(void)
{
digitalWrite(pinEnable, LOW);
}
int main(void)
{
wiringPiSetupGpio();
pinMode(pinEnable, OUTPUT);
pinMode(pinPositive, OUTPUT);
pinMode(pinNegative, OUTPUT);
int i;
for(i=0; i<2; i++)
{
pinMode(aPinSwitch[i], INPUT);
}
wiringPiISR(aPinSwitch[0], INT_EDGE_RISING, motorSpin);
wiringPiISR(aPinSwitch[1], INT_EDGE_FALLING, motorStop);
return 0;
}
'코딩 > Raspberry Pi (c)' 카테고리의 다른 글
라즈베리파이 PIEZO BUZZER 코드 (0) | 2019.11.17 |
---|---|
라즈베리파이 초음파 거리 센서 ULTRASONIC 코드 (0) | 2019.11.17 |
라즈베리파이 PIR센서 코드 (0) | 2019.11.16 |
라즈베리파이 SWITCH 코드 (0) | 2019.11.15 |
라즈베리파이 만든건 전부 프로젝트에 (0) | 2019.05.24 |