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.
Mediul de dezvoltare pentru acest proiect a fost Arduino IDE. Biblioteci utilizate:
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 // ....... } } // ......
void loop() { /* Start conversion */ ADCSRA |= (1 << ADSC); /* Wait until conversion is complete */ while(!(ADCSRA & ( 1 << ADIF))); /* Save result */ uint16_t result = ADC; /* Get brightness */ int brightness = ADC / 4; // ...... }
SparkFun_APDS9960 apds = SparkFun_APDS9960(); int isr_flag = 0; // .... voide setup() { // Other setups // .... setup_interrupts(); // .... // Initialise gesture sensor if ( apds.init() ) { Serial.println(F("APDS-9960 initialization complete")); } else { Serial.println(F("Something went wrong during APDS-9960 init!")); } if ( apds.enableGestureSensor(true) ) { Serial.println(F("Gesture sensor is now running")); } else { Serial.println(F("Something went wrong during gesture sensor init!")); } // .... } void setup_interrupts() { // .... // Extern interrupt EIMSK |= (1 << INT0); // .... } void loop() { // .... // If lamp on // .... if( isr_flag == 1 ) { lights = handleGesture(); isr_flag = 0; } switch (lights) { case 1: // Turn on all LEDs // .... break; case 2: // Turn on yellow LED // .... break; case 3: // Turn on blue LED // .... case 4: // Turn on red LED // .... break; } } else { // Turn off all LEDs // .... } // .... } int handleGesture() { if ( apds.isGestureAvailable() ) { // Return by case of gesture switch ( apds.readGesture() ) { case DIR_UP: // .... return 1; case DIR_DOWN: // .... return 2; case DIR_LEFT: // .... return 3; case DIR_RIGHT: // .... return 4; default: // .... } } }
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.