2017년 5월 18일 목요일
디지털, 아날로그 입출력
//////////FND자동카운터
int i,j;
int pin = 7;
int switchState1 = 0;
int switchState2 = 0;
int myDelay = 50;
int prevState1 = 0;
int prevState2 = 0;
int STATUS1 = 0;
int STATUS2 = 0;
int table[16][7] = {
{1,1,1,1,1,1,0}, //0
{0,1,1,0,0,0,0}, //1
{1,1,0,1,1,0,1}, //2
{1,1,1,1,0,0,1}, //3
{0,1,1,0,0,1,1}, //4
{1,0,1,1,0,1,1}, //5
{1,0,1,1,1,1,1}, //6
{1,1,1,0,0,1,0}, //7
{1,1,1,1,1,1,1}, //8
{1,1,1,0,0,1,1}, //9
{1,1,1,0,1,1,1}, //A
{0,0,1,1,1,1,1}, //B
{0,0,0,1,1,0,1}, //C
{0,1,1,1,1,0,1}, //D
{1,0,0,1,1,1,1}, //E
{1,0,0,0,1,1,1} //F
};
void setup() {
fnd(0);
pinMode(2,INPUT);
pinMode(3,INPUT);
for(i=0; i<7; i++)
pinMode(pin+i, OUTPUT);
}
void fnd(int num)
{
j = num;
for(i=0; i<7; i++)
{
digitalWrite(pin+i, table[j][i]);
}
}
void loop() {
switchState1 = digitalRead(2);
switchState2 = digitalRead(3);
delay(myDelay);
if (switchState1 == 1)
{
for(STATUS1=0; STATUS1<16; STATUS1++)
{
fnd(STATUS1);
delay(500);
}
}
if (switchState2 == 1)
{
for(STATUS2=15; STATUS2>=0; STATUS2--)
{
fnd(STATUS2);
delay(500);
}
}
if ((switchState1 == 1) && (switchState2 == 1))
{
fnd(0);
}
delay(myDelay);
}
//////////////가변저항 아날로그입출력
void setup()
{
Serial.begin(9600);
}
void loop()
{
int analogValue0 = analogRead(A0);
analogValue0 = map(analogValue0, 0, 1023, 0, 255);
analogWrite(5,analogValue0);
Serial.print("analogValue0 = ");
Serial.println(analogValue0);
delay(50);
}
////////////조그스틱 입출력
void setup()
{
Serial.begin(9600);
}
void loop()
{
int analogValue0 = analogRead(A0);
int analogValue1 = analogRead(A1);
analogWrite(5,analogValue0);
analogWrite(6,analogValue1);
Serial.print("( ");
Serial.print(analogValue0);
Serial.print(" , ");
Serial.print(analogValue1);
Serial.print(" )");
Serial.print("\n");
delay(300);
}
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기