KontrolIR V1.00.ino: Difference between revisions

From AnalysIR WiKi
Jump to navigation Jump to search
mNo edit summary
No edit summary
Line 6: Line 6:
* First we init the MCU frequncy divider to match the setting selected in the Arduino IDE.  The crystal used is 16MHz, so for 8MHz operation the clock needs to be divided by a factor of 2. We suggest using 8Mhz with this firmware for the best balance between battery and IR performance. With other firmware loaded ''(e.g. IRremote)'', by all means use 16MHz etc.
* First we init the MCU frequncy divider to match the setting selected in the Arduino IDE.  The crystal used is 16MHz, so for 8MHz operation the clock needs to be divided by a factor of 2. We suggest using 8Mhz with this firmware for the best balance between battery and IR performance. With other firmware loaded ''(e.g. IRremote)'', by all means use 16MHz etc.
* Then we initialise all non-keypad related pins - for the optional IR receivers and I2C EEPROM snd their related power supply via GPIO. The default state for these devices is powered dowm.
* Then we initialise all non-keypad related pins - for the optional IR receivers and I2C EEPROM snd their related power supply via GPIO. The default state for these devices is powered dowm.
* Next we init the keypad buttons. Each button is mapped to a particular Row/Col combination.''(see section on pin outs)'' The 7 Cols are defaulted to INPUT_PULLUP and the 7 Rows are defaulted to OUTPUT LOW. This allows us to make use of PCINT interrupts on the COL pins to detect when a button is pressed during PWR_DOWN mode. Once the MCU wakes up ''(Triggered by the PCINT)'', we cimmediately check to see which COL was pulled LOW and search each ROW to find the actual button that was pressed. If more than one button was pressed we assume the first one found is the one that was pressed.
* Next we init the keypad buttons. Each button is mapped to a particular Row/Col combination.''(see section on pin outs)'' The 7 Cols are defaulted to INPUT_PULLUP and the 7 Rows are defaulted to OUTPUT LOW. This allows us to make use of PCINT interrupts on the COL pins to detect when a button is pressed during PWR_DOWN mode. Once the MCU wakes up ''(Triggered by the PCINT interrupt)'', we immediately check to see which COL was pulled LOW and then search each ROW to find the actual button that was (is still) pressed. If more than one button was pressed we assume the first one found is the one that was pressed. Users could extend this logic to suppor tmultiple key presses etc.
* Next we init the LED pin as output and set it LOW. This is oneof a set of LED macros defined in the header file.
* Next we init the LED pin as output and it defaults LOW or off. This is one of a set of LED control macros available in the header file.
* Then we output a set of debug info over Serial, if  debug mode is on. We also check to see if we are runnign on battery or no. If the supply voltage is greaer than 4 Volts we assume we are being powered by USB, otherwise by the 2xAAA batteries. KontroLIR is never put to sleep when powered from USB.
* Then we output a set of debug info over Serial, if  debug mode is on. We also check to see if we are runnign on battery or not. If the supply voltage is greater than 4 Volts we assume we are being powered by USB, otherwise by the 2xAAA batteries. KontroLIR is never put to sleep when powered from USB.
* Next we in the low pwer mode setting for sleeping. essentiall we turn off any unneccessary peripherals to reduce power consumtions and set the sleep mode to PWR_DOWM.
* Next we init the low power mode settings for sleeping. Essentially we turn off any unneccessary peripherals to reduce power consumption and set the sleep mode to PWR_DOWM.
*  Then we init the Pin change interrupts on the COL pins and subsequently enable teh relevant PCINT interrupts.
*  Then we init the Pin change interrupts on the COL pins and subsequently enable the relevant PCINT interrupts.


At teh end of the setup function, control automatically passes to the loop portion of the firmware.
At the end of the setup function, control automatically passes to the loop portion of the firmware.





Revision as of 04:13, 8 October 2019

> KontroLIR Home > back

This is the min Arduino sketch file, containing both the setup and loop functions.

Setup

  • First we init the MCU frequncy divider to match the setting selected in the Arduino IDE. The crystal used is 16MHz, so for 8MHz operation the clock needs to be divided by a factor of 2. We suggest using 8Mhz with this firmware for the best balance between battery and IR performance. With other firmware loaded (e.g. IRremote), by all means use 16MHz etc.
  • Then we initialise all non-keypad related pins - for the optional IR receivers and I2C EEPROM snd their related power supply via GPIO. The default state for these devices is powered dowm.
  • Next we init the keypad buttons. Each button is mapped to a particular Row/Col combination.(see section on pin outs) The 7 Cols are defaulted to INPUT_PULLUP and the 7 Rows are defaulted to OUTPUT LOW. This allows us to make use of PCINT interrupts on the COL pins to detect when a button is pressed during PWR_DOWN mode. Once the MCU wakes up (Triggered by the PCINT interrupt), we immediately check to see which COL was pulled LOW and then search each ROW to find the actual button that was (is still) pressed. If more than one button was pressed we assume the first one found is the one that was pressed. Users could extend this logic to suppor tmultiple key presses etc.
  • Next we init the LED pin as output and it defaults LOW or off. This is one of a set of LED control macros available in the header file.
  • Then we output a set of debug info over Serial, if debug mode is on. We also check to see if we are runnign on battery or not. If the supply voltage is greater than 4 Volts we assume we are being powered by USB, otherwise by the 2xAAA batteries. KontroLIR is never put to sleep when powered from USB.
  • Next we init the low power mode settings for sleeping. Essentially we turn off any unneccessary peripherals to reduce power consumption and set the sleep mode to PWR_DOWM.
  • Then we init the Pin change interrupts on the COL pins and subsequently enable the relevant PCINT interrupts.

At the end of the setup function, control automatically passes to the loop portion of the firmware.


Loop


> KontroLIR Home > back