![]() |
|
![]() |
#1 |
Moderator
Регистрация: 20.07.2014
Адрес: МСК
Сообщений: 991
Вес репутации: 1031 ![]() ![]() ![]() |
![]()
После многих неудач, свершилось.
Настенный выключатель готов на 80%. TODO: 1. Очень многое пришлось изменить. Подрезать, подклеить, подсверлить... По хорошему надо перепечатать начисто. 2. Написать программу для atmeg фото. Не получилось на телефон сфотографировать правдоподобноВсё выключено:
По периметру подсвечено синим, надо будет увеличить резисторы, чтоб мягче светилось. По хорошему нужны световоды, для рассеивания. Но пока это выше моих сил. Включен правый верхний. Синий светодиод погашен, включен белый. И общий вид при естественном освещении: [свернуть] Бюджет: 1. Рамка - 500р. 2. Комплект пластиковых деталей - подарок постоянному клиенту. Оцениваю в 250р. там все тонкое. 3. ProMini - 98р 4. Плата с радиодеталями - за большое спасибо подарены форумчанином (в теме про ЛУТ он не отметился, может хочет сохранить инкогнито. 5. Кнопки 7р *4шт = 28р. 6. Светодиоды 3528 1р * 8шт = 8р. Итого около 1000р, не считая неудачных попыток и антидеприсантов ![]() В случае распайки микроконтроллера на основную плату, выключатель полностью умещается в рамку и не требует подрозетника. Закинуть что-ли на кикстартер? в производстве можно и RGBW светодиоды использовать. Цвет настраивается под настроение. Может китайцы идею оттуда утащат. |
![]() |
![]() |
![]() |
#2 |
Moderator
Регистрация: 20.07.2014
Адрес: МСК
Сообщений: 991
Вес репутации: 1031 ![]() ![]() ![]() |
![]()
Тестовый код, для мигания светодиодами на самом выключателе:
Развернуть для просмотраКод:
/* based on http://www.arduino.cc/en/Tutorial/Debounce created 21 November 2006 by David A. Mellis modified 30 Aug 2011 by Limor Fried modified 28 Dec 2012 by Mike Walters */ //D3-D6 - светодиоды //D10-D13 (PB2-PB5)кнопки, на землю // constants won't change. They're used here to // set pin numbers: const int buttonPin[] = {10,11,12,13}; // the number of the pushbutton pin const int ledPin[] = {4,5,6,3}; // the number of the LED pin // Variables will change: int ledState[] = {HIGH,HIGH,HIGH,HIGH}; // the current state of the output pin int buttonState[]= {HIGH,HIGH,HIGH,HIGH}; // the current reading from the input pin int lastButtonState[] = {HIGH,HIGH,HIGH,HIGH}; // the previous reading from the input pin // the following variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long lastDebounceTime[] = {0,0,0,0}; // the last time the output pin was toggled long debounceDelay = 50; // the debounce time; increase if the output flickers void setup() { int i; for (i = 0; i < 4; i++) { pinMode(buttonPin[i], INPUT); digitalWrite(buttonPin[i], HIGH); pinMode(ledPin[i], OUTPUT); // set initial LED state digitalWrite(ledPin[i], ledState[i]); } } void loop() { int i; int reading[4]; for (i = 0; i < 4; i++) { // read the state of the switch into a local variable: reading[i] = digitalRead(buttonPin[i]); // check to see if you just pressed the button // (i.e. the input went from LOW to HIGH), and you've waited // long enough since the last press to ignore any noise: // If the switch changed, due to noise or pressing: if (reading[i] != lastButtonState[i]) { // reset the debouncing timer lastDebounceTime[i] = millis(); } if ((millis() - lastDebounceTime[i]) > debounceDelay) { // whatever the reading is at, it's been there for longer // than the debounce delay, so take it as the actual current state: // if the button state has changed: if (reading[i] != buttonState[i]) { buttonState[i] = reading[i]; // only toggle the LED if the new button state is LOW if (buttonState[i] == LOW) { ledState[i] = !ledState[i]; } } } // set the LED: digitalWrite(ledPin[i], ledState[i]); // save the reading. Next time through the loop, // it'll be the lastButtonState: lastButtonState[i] = reading[i]; } } [свернуть] отрабатывает без проблем. Пришлось перерезать дорожку к сигнальному LED ардуины, иначе он гасит подтяжку порта. |
![]() |
![]() |
![]() |
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1) | |
|
|