제로부터 시작하는 극한의 아두이노 DIY생활 - 응용4

in hive-139150 •  2 years ago 

안녕하세요! Jimae입니다.!!

요새 바쁜나날이지만... 가...가...가..즈...ㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏㅏ

image.png

자 이제 저번에 가라로 짠 프로그램을 검증하기 위해 직접 하드웨어를 만들어 볼까요?

image.png

image.png

우선 하드웨어 디버깅 하느라 고생했습니다. ㅠㅠ

왜냐하면 가지고 있는 전선들과 저항이 불량인게 많내요.

겉으로는 멀쩡해보이나 속은 안좋아서 그런지 전기가 제대로 안통해서 찾느라 애좀먹었습니다.

image.png

gif 파일이 안올라가내요 ㅠㅠ

우선 생각한대로 동작은 완성했습니다.

물론 디버깅하느라 프로그램적으로 몇가지 추가한게 있습니다.

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 11;     // the number of the pushbutton pin
const int ledPin =  12;      // the number of the LED pin
const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int programState = 0;

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(analogInPin, INPUT);
   
  Serial.begin(9600);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  int sensorValue = 0;        // value read from the pot

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    if(programState == 0)
    {
      programState = 1;
      Serial.println("on");
    }
    else
    {
      programState = 0;
      Serial.println("off");
      digitalWrite(ledPin, LOW);
    }
  } 

  if(programState == 1)
  {
    sensorValue = analogRead(analogInPin);
    // print the results to the Serial Monitor:
    Serial.print("sensor = ");
    Serial.println(sensorValue);

    if(sensorValue < 512)
    {
       digitalWrite(ledPin, LOW);
    }
    else
    {
       digitalWrite(ledPin, HIGH);
    }
  }

  delay(50);
}

delay 를 50ms 단위로 바꾸었구요.

print를 좀더 찍었습니다.

물론 이게 완벽한 소스는 아닙니다. 되게 초보적이지만 몇가지 문제가 있어요.

그부분은

image.png

스위치 부분입니다.

이부분을 해결하기 위해서는 왜이런식으로 동작하는지 알아야하는대 이건 다음에 알려드릴거구요!

저번에 올린 소스보다 이번꺼를 참고해서 사용해주시길 바랍니다.

이건 검증이 끝나서 동작을 했습니다!!

물론 ㅠㅠ gif 파일이 안올라가서 인증을 못한게 아쉽군요.

다음날에 괜찮을때 이글에 수정해서라도 이미지를 올려보도록 하겠습니다.

사실 디버깅하느라 정신력을 다 소모 해버린듯 합니다. ㅎㅎㅎㅎㅎㅎㅎㅎㅎㅎㅎㅎ

다들 좋은 하루 되세요.

제로부터 시작하는 극한의 아두이노 DIY생활 - 응용1
제로부터 시작하는 극한의 아두이노 DIY생활 - 응용2
제로부터 시작하는 극한의 아두이노 DIY생활 - 응용3

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  

image.png

Google pays for every Person every hour online working from home. I have received $23K this month easily and I earn $5K to 8$K on the internet. Every Person joins this work easily by just opening this website and following instructions…
https://www.online.hiring9.com/

즐거운 날 되세요~~^^

!shop