AT407 ±â¿ï±â ¼¾¼ÀÔ´Ï´Ù. ¾ÈÂÊÀÇ °øÀÌ ¼¾¼ÀÇ ¿¬°áÀ» °áÁ¤Çϸç ÀÌ·Î½á ´Ü¶ôÀÌ °áÁ¤µË´Ï´Ù. ÀÏ¹Ý ½ºÀ§Ä¡ »ç¿ë ¹æ¹ý°ú ºñ½ÁÇÕ´Ï´Ù.
°ü·Ã ¹®¼
»ç¿ë ¿¹Á¦ ±â¿ï±â ¼¾¼·Î ´ÙÀ½°ú °°ÀÌ È¸·Î¸¦ ±¸¼ºÇؼ ±â¿ï±â¸¦ °¨ÁöÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀúÇ×Àº 10K ÀúÇ×À» Ç®¾÷À¸·Î »ç¿ëÇÏ¿´½À´Ï´Ù.
¾ÆµÎÀÌ³ë ¼Ò½ºÄÚµå
- int inPin = 2; // the number of the input pin
- int outPin = 13; // the number of the output pin
-
- int LEDstate = HIGH; // the current state of the output pin
- int reading; // the current reading from the input pin
- int previous = LOW; // the previous reading from the input pin
-
- // the follow variables are long's because the time, measured in miliseconds,
- // will quickly become a bigger number than can be stored in an int.
- long time = 0; // the last time the output pin was toggled
- long debounce = 50; // the debounce time, increase if the output flickers
-
- void setup()
- {
- pinMode(inPin, INPUT);
- digitalWrite(inPin, HIGH); // turn on the built in pull-up resistor
- pinMode(outPin, OUTPUT);
- }
-
- void loop()
- {
- int switchstate;
-
- reading = digitalRead(inPin);
-
- // If the switch changed, due to bounce or pressing...
- if (reading != previous) {
- // reset the debouncing timer
- time = millis();
- }
-
- if ((millis() - time) > debounce) {
- // whatever the switch is at, its been there for a long time
- // so lets settle on it!
- switchstate = reading;
-
- // Now invert the output on the pin13 LED
- if (switchstate == HIGH)
- LEDstate = LOW;
- else
- LEDstate = HIGH;
- }
- digitalWrite(outPin, LEDstate);
-
- // Save the last reading so we keep a running tally
- previous = reading;
- }
Description: This AT407 basic tilt switch can easily be used to detect orientation. Inside the can are a pair of balls that make contact with the pins when the case is upright. Tilt the case over and the balls don¡¯t touch, thus not making a connection. There are numerous uses for these basic sensors, but keep in mind you might need to use some debouncing code, as the sensor isn¡¯t immune to small vibrations and such. Documents:
|