This is an old revision of the document!
Scopul acestui proiect este realizarea unei lămpi inteligente care reflectă starea utilizatorului. Ideea a provenit de la dorința de a face un proiect interactiv care poate fi folosit zilnic de utilizator. Lampa intelgientă se poate dovedi utilă pentru a crea un ambient în concordanță cu starea utilizatorului sau pentru a-i oferi starea dorită (exemplu: albastru este o culoare ce calmează).
Culoarea lămpii se va schimba în funcție de gesturile utilizatorului cu ajutorul unui senzor de gesturi astfel:
Lampa se va opri automat după o perioadă de 60 de secunde. Apăsând pe buton, utilizatorul va putea opri/porni lampa. De asemenea, utilizatorul va putea seta și intensitatea luminii cu ajutorul unui potențiometru.
Implementare:
#define BUTTON PD4
int counter = 0;
int buttonState = HIGH;
int lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 100;
int seconds = 0;
// Other initializations
// .......
void setup() {
// Initialize Serial port
Serial.begin(9600);
// Initialize interrupts
setup_interrupts();
// Setup code here
// .....
}
void setup_interrupts() {
// Enable pin change interrupt (for button)
PCMSK2 |= (1 << PCINT20);
// Set PCIE2 to enable PCMSK2 scan
PCICR |= (1 << PCIE2);
TIMSK1 |= (1 << OCIE1A); // enable interrupts TIMER1_COMPA
}
void loop() {
// Potentiometer code
// ......
/* If counter odd number, lamp is on
if the seconds limit has not been reached
execute tasks */
if (counter % 2 == 1 && seconds < TIME_LIMIT) {
// Handle gesture sensor
// ......
} else {
// Turn off lamp
// ......
}
}
ISR(TIMER1_COMPA_vect) {
// Interrupt code for TIMER1
get_time();
}
void get_time() {
// Increments number of seconds
seconds++;
// If the limit is reached
if (seconds >= TIME_LIMIT) {
// Turn off all LEDs
// .....
// Give counter even value for knowing
// that the lamp is off
counter = 0;
}
}
// ......
ISR(PCINT2_vect) {
// Debounce code for button
// .......
// If valid button press has occurred
if (buttonState == HIGH && digitalRead(4) == LOW) {
// Increment counter
counter++;
// Reset timer
time = 0;
}
// Updates
// .......
}
}
// ......
Fişierele se încarcă pe wiki folosind facilitatea Add Images or other files. Namespace-ul în care se încarcă fişierele este de tipul :pm:prj20??:c? sau :pm:prj20??:c?:nume_student (dacă este cazul). Exemplu: Dumitru Alin, 331CC → :pm:prj2009:cc:dumitru_alin.