static void onKeyPressed(uint8_t key) { switch(key) { case KEY_PLUS: if (timer_mode == TIMER_MODE_WAIT && timer_interval < MAX_TIME_INTERVAL_MINUTES) { timer_interval++; } break; case KEY_MINUS: if (timer_mode == TIMER_MODE_WAIT && timer_interval > 0) { timer_interval--; } break; case KEY_ENTER: if (timer_mode == TIMER_MODE_WAIT) { eeprom_update_word(EEPROM_OFFSET_TIME, timer_interval); time = timer_interval * 60; enableLed(true); enablePower(true); timer_mode = TIMER_MODE_RUN; } break; case KEY_BACK: if (timer_mode == TIMER_MODE_RUN) { timer_mode = TIMER_MODE_WAIT; enableLed(false); enablePower(false); } break; } }
int main(void) { DDRD = 0xff; DDRB = 0xff; DDRC = 0; PORTC = _BV(2) | _BV(3) | _BV(4) | _BV(5); // keyboard pull-up TCCR1A = 0; TCCR1B = _BV(CS11) | _BV(CS10); TIMSK = _BV(OCIE1A); sei(); enableLed(false); enablePower(false); displayOutTime(0); timer_interval = eeprom_read_word(EEPROM_OFFSET_TIME); if (timer_interval > MAX_TIME_INTERVAL_MINUTES || timer_interval == 0) { timer_interval = 10; } while(1) { keyboardCheck(); if (timer_mode == TIMER_MODE_WAIT) { if (key_pressed[KEY_PLUS] == 0xff && timer_interval < MAX_TIME_INTERVAL_MINUTES) { timer_interval++; key_pressed[KEY_PLUS] = 220; } else if (key_pressed[KEY_MINUS] == 0xff && timer_interval > 0) { timer_interval--; key_pressed[KEY_MINUS] = 220; } } for (uint8_t i = 0; i < 8; i++) { displayUpdate(i); if (timer_mode == TIMER_MODE_RUN) { displayOutTime(time); displayOutSeparator(hsec < 50); if (time < 30) { enableLed(hsec < 25 || (hsec > 50 && hsec < 75)); } else if (time < 60) { enableLed(hsec < 75); } } else { displayOutTime(timer_interval); displayOutSeparator(true); //displayOutSeparator(hsec < 25 || (hsec > 50 && hsec < 75)); //if (hsec < 25 || (hsec > 50 && hsec < 75)) { //displayOutTime(timer_interval); //displayOutSeparator(true); //} else { //displayClear(); //} } _delay_us(500); } } }
/* ----------------------------------------------------------------------------* * * Function Name : enableGestureSensor(int interrupts) * * Description :Starts the gesture recognition engine on the APDS-9960 * * Input : interrupts true to enable hardware external interrupt on gesture * * Output : None * * Return : True if engine enabled correctly. False on error. * ----------------------------------------------------------------------------* * Authors: Sarath S * Date: May 17, 2017 * ---------------------------------------------------------------------------*/ int enableGestureSensor(int interrupts) { /* Enable gesture mode Set ENABLE to 0 (power off) Set WTIME to 0xFF Set AUX to LED_BOOST_300 Enable PON, WEN, PEN, GEN in ENABLE */ resetGestureParameters(); if( !i2c1_write(APDS9960_WTIME, 0xFF) ) { return false; } if( !i2c1_write(APDS9960_PPULSE, DEFAULT_GESTURE_PPULSE) ) { return false; } if( !setLEDBoost(LED_BOOST_300) ) { return false; } if( interrupts ) { if( !setGestureIntEnable(1) ) { return false; } } else { if( !setGestureIntEnable(0) ) { return false; } } if( !setGestureMode(1) ) { return false; } if( !enablePower() ){ return false; } if( !setMode(WAIT, 1) ) { return false; } if( !setMode(PROXIMITY, 1) ) { return false; } if( !setMode(GESTURE, 1) ) { return false; } return true; }/* End of this function */
void enable_gesture() { resetGestureParameters(); wireWriteDataByte(APDS9960_WTIME, 0xFF); wireWriteDataByte(APDS9960_PPULSE, DEFAULT_GESTURE_PPULSE); setLEDBoost(LED_BOOST_300); setGestureIntEnable(1); setGestureMode(1); enablePower(); setMode(WAIT, 1); setMode(PROXIMITY, 1); setMode(GESTURE, 1); }
void nRF24L01::begin(uint8_t ad0, uint8_t ad1, uint8_t ad2, uint8_t ad3, uint8_t ad4, uint8_t chan, uint8_t width) { _spi->begin(); _spi->setSpeed(10000000UL); _addr[0] = ad0; _addr[1] = ad1; _addr[2] = ad2; _addr[3] = ad3; _addr[4] = ad4; _pipeWidth = width; pinMode(_csn, OUTPUT); pinMode(_ce, OUTPUT); pinMode(_intr, INPUT); digitalWrite(_csn, HIGH); digitalWrite(_ce, HIGH); setChannel(chan); regSet(REG_CONFIG, 2); uint8_t zero = 0x00; regWrite(REG_EN_AA, &zero, 1); _bc[0] = 0xFF; _bc[1] = 0xFF; _bc[2] = 0xFF; _bc[3] = 0xFF; _bc[4] = 0xFF; enablePipe(0, _bc, false); enablePipe(1, _addr, true); selectRX(); switch (isrHandlerCounter) { case 0: isrObject0 = this; attachInterrupt(_intr, nRF24L01_isrHandler0, FALLING); break; case 1: isrObject1 = this; attachInterrupt(_intr, nRF24L01_isrHandler1, FALLING); break; case 2: isrObject2 = this; attachInterrupt(_intr, nRF24L01_isrHandler2, FALLING); break; case 3: isrObject3 = this; attachInterrupt(_intr, nRF24L01_isrHandler3, FALLING); break; case 4: isrObject4 = this; attachInterrupt(_intr, nRF24L01_isrHandler4, FALLING); break; case 5: isrObject5 = this; attachInterrupt(_intr, nRF24L01_isrHandler5, FALLING); break; case 6: isrObject6 = this; attachInterrupt(_intr, nRF24L01_isrHandler6, FALLING); break; case 7: isrObject7 = this; attachInterrupt(_intr, nRF24L01_isrHandler7, FALLING); break; } isrHandlerCounter++; uint32_t s = disableInterrupts(); digitalWrite(_csn, LOW); _status = _spi->transfer(CMD_TX_FLUSH); digitalWrite(_csn, HIGH); digitalWrite(_csn, LOW); _status = _spi->transfer(CMD_RX_FLUSH); digitalWrite(_csn, HIGH); restoreInterrupts(s); uint8_t isrstat = 0x70; regWrite(REG_STATUS, &isrstat, 1); isrstat = 0xFF; regWrite(REG_SETUP_RETR, &isrstat, 1); enablePower(); }
TSL2561_I2C::TSL2561_I2C( PinName sda, PinName scl ) : i2c( sda, scl ){ i2c.frequency(100000); enablePower(); }