Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
24d3284
initial framework branch, moving click_counter to its own file.
dhiltonp Sep 21, 2013
2c4f368
library: split off utilities, input_digit, print_number
dhiltonp Sep 21, 2013
3aa53a4
library: moved utilities to libraries/hb_utilities
dhiltonp Sep 23, 2013
56aa02d
library: utilities.* changed to print_power.*
dhiltonp Sep 23, 2013
62fa960
library: split off stroboscope code into hb_utilities
dhiltonp Sep 23, 2013
ab4b72a
programs: tactical, up_n_down now work with print_power
dhiltonp Sep 23, 2013
ef571c7
hb_utilities: flip_color moved from print_power to print_number
dhiltonp Sep 23, 2013
da32501
library: hexbright/includes moved to hexbright, renamed to pc_stubs, …
dhiltonp Sep 23, 2013
2d503a5
twi: moved to hexbright/twi, so it is automatically pulled in by incl…
dhiltonp Sep 23, 2013
aae542a
library: added readme
dhiltonp Sep 23, 2013
3fce0cd
library/readme: added description of 3 key directories
dhiltonp Sep 23, 2013
c8af028
Update README.md
dhiltonp Sep 23, 2013
64fbc38
updated all programs to work with the current framework version
dhiltonp Sep 27, 2013
5abc3be
Merge branch 'master' into framework
dhiltonp Sep 27, 2013
43508b3
hb_utilities: added print_binary, which prints binary representations…
dhiltonp Sep 27, 2013
8c822e8
library: removed shutdown (deprecated method)
dhiltonp Sep 28, 2013
d409eff
spin_level: moved to programs, added a readme, slightly altered behavior
dhiltonp Oct 8, 2013
938568c
all programs: added inline comment documenting BUILD_HACK
dhiltonp Nov 10, 2013
6e363b3
hb_utilities/print_binary.h: commented out dependency on Serial.h and…
dhiltonp Nov 26, 2013
3d711f6
hexbright.h: allow DEBUG to be permanantly set on a per-program basis
dhiltonp Feb 4, 2014
e139051
hexbright.h: split out set_light_level, allow for #define selection o…
dhiltonp Feb 4, 2014
e2a45fe
Fix two small errors in comments/documentation
soult Feb 21, 2014
b0690ee
Merge pull request #41 from soult/comments
dhiltonp Feb 21, 2014
211620f
updated note on power consumption
dhiltonp Mar 7, 2014
7b66f42
added Bike Light program
andyseubert Mar 28, 2014
7784bd1
fixed some comments Bike Light program
andyseubert Mar 28, 2014
c066183
Merge pull request #42 from andyseubert/master
dhiltonp Mar 30, 2014
d8e154d
added new boards.txt for Arduino 1.5 compatibility. Thanks to Josh Go…
dhiltonp Apr 7, 2014
95570e6
Add new program that is similar to up_n_down
mcsarge Aug 8, 2014
9f7abb0
Near final change to the new program
mcsarge Aug 9, 2014
9f5d92f
Update comments and minor changes
mcsarge Aug 10, 2014
33699e7
Auto formatted
mcsarge Aug 10, 2014
d6332f2
Merge pull request #51 from mcsarge/master
dhiltonp Aug 11, 2014
88d49ab
Tail Flash
mcsarge Aug 13, 2014
9a698fa
Merge pull request #52 from mcsarge/master
dhiltonp Aug 13, 2014
e2a3721
Update README.md
mcsarge Aug 14, 2014
fe1edac
SOS Rewrite
mcsarge Aug 21, 2014
199ebbb
Update README.md
mcsarge Aug 21, 2014
ed950ba
More tuning to Mode SOS
mcsarge Aug 22, 2014
a2a3029
Merge branch 'master' of https://github.com/mcsarge/hexbright
mcsarge Aug 22, 2014
b2e1807
New feature of Locked Mode and documentation updates.
mcsarge Aug 29, 2014
4cf173d
Update README.md
mcsarge Aug 29, 2014
57e730a
Various Documentation Updates
mcsarge Aug 29, 2014
f280ac4
Merge pull request #53 from mcsarge/master
dhiltonp Aug 29, 2014
2e42d1f
port new lock mode and sos mode from set_and_remember
Aug 31, 2014
8d31ace
Merge pull request #54 from wbattestilli/master
dhiltonp Aug 31, 2014
cab50c3
Fixed the shutdown error
mcsarge Sep 9, 2014
5a22333
Documentation
mcsarge Sep 9, 2014
ddc8c98
Merge pull request #55 from mcsarge/master
dhiltonp Sep 9, 2014
6360910
Upload MCU pinout
DiHydro Jan 11, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ I have translated most of the original sample programs to the library here: http

Be aware that this library is a work in progress. In particular,<br>
* the accelerometer api will change
* power consumption ~~has not been optimized~~ [is about as good as it is going to get](https://github.com/dhiltonp/hexbright/tree/master/experiments/power_draw#optimizing-power-draw).
* power consumption has not been optimized ~~is about as good as it is going to get~~ [(see notes)](https://github.com/dhiltonp/hexbright/tree/master/experiments/power_draw#optimizing-power-draw).

Enjoy!

Expand Down
12 changes: 12 additions & 0 deletions experiments/power_draw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ consumes 80-90% of the 5.4 mA in standby. This would vary based on the differenc
I believe Christian put the power regulator at its point in order to prevent any power draw when the light is off,
but as a consequence the standby time is 5-10x shorter than it would otherwise be.

I need to run some numbers, calculating the difference between expected and observed power loss.

Formula for power loss in the voltage regulator: [(4.2 - 3.3) * .500 + (4.2*.09)](http://en.wikipedia.org/wiki/Low-dropout_regulator#Efficiency_and_Heat_Dissipation)<br>
.5 milliamps consumed by other components would cause a power loss of .83 milliamps, with 1.33 milliamps used<br>
1 milliamp consumed, loss of 1.27 milliamps, 2.27 milliamps used<br>
2 milliamps consumed, loss of 2.178, 4.178 milliamps used<br>
3 milliamps consumed, loss of 3.078, 6.078 milliamps used<br>

2.64 milliamps consumed, loss of 2.75 milliamps would be 5.4 milliamps used.
We are probably powering about 2.64 milliamps. Lowering the power used for each device will roughly double the savings listed on the data sheet.


Raw Data
--------
Recorded with a Fluke 287
Expand Down
Binary file added hardware/hexbright/HexBright-Schematic-MCU.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 48 additions & 0 deletions hardware/hexbright/avr/boards.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
##############################################################

hexbright.name=Hexbright

hexbright.upload.protocol=arduino
hexbright.upload.tool=arduino:avrdude
hexbright.upload.maximum_size=14336
hexbright.upload.maximum_data_size=1024
hexbright.upload.speed=19200

hexbright.bootloader.low_fuses=0xe2
hexbright.bootloader.high_fuses=0xdd
hexbright.bootloader.extended_fuses=0x00
hexbright.bootloader.path=hexbright:atmega
hexbright.bootloader.file=ATmegaBOOT_168_hexbright.hex
hexbright.bootloader.unlock_bits=0x3F
hexbright.bootloader.lock_bits=0x0F

hexbright.build.mcu=atmega168
hexbright.build.f_cpu=8000000L
hexbright.build.core=arduino:arduino
hexbright.build.variant=arduino:standard


##############################################################

hexbright_tiny.name=Hexbright Tinyboot

hexbright_tiny.upload.protocol=arduino
hexbright_tiny.upload.tool=arduino:avrdude
hexbright_tiny.upload.maximum_size=15360
hexbright_tiny.upload.maximum_data_size=1024
hexbright_tiny.upload.speed=19200

hexbright_tiny.bootloader.low_fuses=0xe2
hexbright_tiny.bootloader.high_fuses=0xdd
hexbright_tiny.bootloader.extended_fuses=0x02
hexbright_tiny.bootloader.path=hexbright:atmega
hexbright_tiny.bootloader.file=ATmegaBOOT_168_hexbright_tiny.hex
hexbright_tiny.bootloader.unlock_bits=0x3F
hexbright_tiny.bootloader.lock_bits=0x0F

hexbright_tiny.build.mcu=atmega168p
hexbright_tiny.build.f_cpu=8000000L
hexbright_tiny.build.core=arduino:arduino
hexbright_tiny.build.variant=arduino:standard


21 changes: 13 additions & 8 deletions hb-examples/alarm_clock/alarm_clock.ino
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include <print_power.h>
#include <print_number.h>
#include <input_digit.h>

// These next two lines must come after all other library #includes
#define BUILD_HACK
#include <hexbright.h>
#include <twi.h>
#include <Time.h>

hexbright hb;
Expand Down Expand Up @@ -35,14 +40,14 @@ void loop() {
mode = SET_MODE;
hb.set_light(0, 150, 300);
}
if(!hb.printing_number()) {
hb.print_charge(GLED);
if(!printing_number()) {
print_charge(GLED);
}
break;
case SET_MODE:
hb.input_digit(duration*10, duration*10+time[place]);
input_digit(duration*10, duration*10+time[place]);
if(hb.button_just_released() && hb.button_pressed_time()<300) {
duration = hb.get_input_digit();
duration = get_input_digit();
place++;
}
if(place==PLACES) {
Expand All @@ -60,9 +65,9 @@ void loop() {
mode = WAKE_MODE;
} else {
// display our current wait time...
if(!hb.printing_number()) {
if(!printing_number()) {
// print hours, and minutes remaining
hb.print_number(duration_remaining(duration));
print_number(duration_remaining(duration));
}
}
break;
Expand All @@ -80,4 +85,4 @@ int duration_remaining(int duration) {
minutes_remaining+=60;
}
return hours_remaining*100+minutes_remaining;
}
}
9 changes: 5 additions & 4 deletions hb-examples/down_light/down_light.ino
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies,
either expressed or implied, of the FreeBSD Project.
*/
#include <print_power.h>

// These next two lines must come after all other library #includes
#define BUILD_HACK
#include <hexbright.h>

#include <twi.h>

hexbright hb;

void setup() {
Expand Down Expand Up @@ -73,5 +74,5 @@ void loop() {
hb.set_light(CURRENT_LEVEL, 200, 50);
}
}
hb.print_power();
}
print_power();
}
13 changes: 8 additions & 5 deletions hb-examples/numeric_input/numeric_input.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <input_digit.h>

// These next two lines must come after all other library #includes
#define BUILD_HACK
#include <hexbright.h>
#include <twi.h>

hexbright hb;

Expand All @@ -16,14 +19,14 @@ unsigned int value = 0;
void loop() {
hb.update();
if(hb.button_just_released() && hb.button_pressed_time()<300) { // on button press, we could do it based on whatever input signal we want.
value = hb.get_input_digit();
value = get_input_digit();
} else if (hb.button_just_released()) {
value = hb.get_input_digit();
value = get_input_digit();
hb.set_light(CURRENT_LEVEL, value<1 ? 1 : value, 300);
value = 0;
} else if (hb.button_just_pressed() && hb.button_released_time()<500) {
hb.set_light(CURRENT_LEVEL, OFF_LEVEL, NOW);
value = 0;
}
hb.input_digit(value*10, value*10+10);
}
input_digit(value*10, value*10+10);
}
25 changes: 14 additions & 11 deletions hb-examples/stroboscope/stroboscope.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// uncomment (delete // before) '#define STROBE' in hexbright.h
#include <strobe.h>
#include <print_number.h>

// These next two lines must come after all other library #includes
#define BUILD_HACK
#include <hexbright.h>
#include <twi.h>

hexbright hb;

Expand All @@ -17,7 +20,7 @@ int mode = OFF_MODE;

void loop() {
hb.update();

if(mode==OFF_MODE) {
if(hb.button_pressed_time()<200 && hb.button_just_released()) {
fpm = 2000;
Expand All @@ -27,7 +30,7 @@ void loop() {
if(mode==STROBE_MODE) {
// turn off?
if (hb.button_pressed_time()>200) {
hb.set_strobe_delay(STROBE_OFF); // if this line doesn't compile, uncomment STROBE in hexbright.h
set_strobe_delay(STROBE_OFF); // if this line doesn't compile, uncomment STROBE in hexbright.h
hb.set_light(CURRENT_LEVEL, OFF_LEVEL, NOW);
mode = OFF_MODE;
return;
Expand All @@ -44,7 +47,7 @@ void loop() {
} while (Serial.available()>0);
if(buffer>0) {
fpm = buffer;
hb.set_strobe_fpm(buffer);
set_strobe_fpm(buffer);
}

char spin = hb.get_spin();
Expand All @@ -54,13 +57,13 @@ void loop() {
else
fpm /= 1+spin/200.0;
//Serial.println(avg_spin);
hb.set_strobe_fpm(fpm);
set_strobe_fpm(fpm);
}

if(!hb.printing_number()) {
Serial.println(hb.get_strobe_fpm());
Serial.println(hb.get_strobe_error());
hb.print_number(hb.get_strobe_fpm());
if(!printing_number()) {
Serial.println(get_strobe_fpm());
Serial.println(get_strobe_error());
print_number(get_strobe_fpm());
}
}
}
}
9 changes: 6 additions & 3 deletions hb-examples/unplugged_action/unplugged_action.ino
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include <print_power.h>

// These next two lines must come after all other library #includes
#define BUILD_HACK
#include <hexbright.h>
#include <twi.h>

hexbright hb;

Expand Down Expand Up @@ -38,12 +41,12 @@ void loop() {
mode=AUTO_OFF_MODE;
auto_off_start_time=millis();
} else { // flash LED because we're plugged in
hb.print_charge(GLED);
print_charge(GLED);
}
} else if (mode==AUTO_OFF_MODE) {
if(millis()-auto_off_start_time > AUTO_OFF_WAIT) {
hb.set_light(CURRENT_LEVEL, OFF_LEVEL, NOW);
}
}
}


14 changes: 14 additions & 0 deletions libraries/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Planned structure in moving to a framework:

3 key directories:

hb_modes - a collection of light modes (like light_spin, light_down, strobe_serial, selector_tap)<br>
hb_utilities - things like print_number, click_counter, advanced
accelerometer interfaces. In general, code that expands on the core
library without any dependencies.<br>
hexbright - core library, plus .h files for overridable
options/behavior (low_battery, overheat, set_light_level)<br>

hexbright functions by itself, but hb_utilities provide convenience functions and in some cases alter the behavior of the core library.

hb_modes simply provides an easy way to customize and share code.
49 changes: 49 additions & 0 deletions libraries/hb_utilities/click_counter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include "click_counter.h"

byte clickState;
byte clickCount;
word max_click_time;

void config_click_count(word click_time) {
max_click_time = click_time;
clickState=0;
}

char click_count() {
switch(clickState) {
case CLICK_OFF:
if(hexbright::button_just_pressed()) {
// click just started
clickState = CLICK_ACTIVE;
clickCount=0;
//Serial.println("Clicking just started");
}
break;
case CLICK_ACTIVE:
if(hexbright::button_just_released()) {
if(hexbright::button_pressed_time() > max_click_time) {
// button held to long
//Serial.println("Click held too long");
clickState = CLICK_OFF;
} else {
// click is counted
clickState = CLICK_WAIT;
clickCount++;
//Serial.println("Click counted");
}
}
break;
case CLICK_WAIT:
// button is released for long enough, we're done clicking
if(hexbright::button_released_time() > max_click_time) {
clickState = CLICK_OFF;
//Serial.print("Click finished: "); Serial.println((int)clickCount);
return clickCount;
} else if(hexbright::button_pressed()) {
// move back to active state
clickState = CLICK_ACTIVE;
//Serial.println("Click active");
}
}
return -127;
}
20 changes: 20 additions & 0 deletions libraries/hb_utilities/click_counter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef CLICK_COUNTER_H
#define CLICK_COUNTER_H


#include "hexbright.h"

#define CLICK_OFF 0
#define CLICK_ACTIVE 1
#define CLICK_WAIT 2

// Call in setup loop if you want to use the click counter
// click_time is the maximum time a click can take before the counter resets
extern void config_click_count(word click_time);

// The number of clicks <= click_time. Will not return a count until click_time ms after the button release.
// Will return -127 unless returning a valid count.
extern char click_count();


#endif //CLICK_COUNTER_H
21 changes: 21 additions & 0 deletions libraries/hb_utilities/input_digit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "input_digit.h"

static unsigned int read_value = 0;

unsigned int get_input_digit() {
return read_value;
}

void input_digit(unsigned int min_digit, unsigned int max_digit) {
unsigned int tmp2 = 999 - atan2(hexbright::vector(0)[0], hexbright::vector(0)[2])*159 - 500; // scale from 0-999, counterclockwise = higher
tmp2 = (tmp2*(max_digit-min_digit))/1000+min_digit;
if(tmp2 == read_value) {
if(!printing_number()) {
print_number(tmp2);
}
} else {
reset_print_number();
hexbright::set_led(GLED,100);
}
read_value = tmp2;
}
19 changes: 19 additions & 0 deletions libraries/hb_utilities/input_digit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef INPUT_DIGIT_H
#define INPUT_DIGIT_H

#include "hexbright.h"
#include "print_number.h"

// reads a value between min_digit to max_digit-1, see hb-examples/numeric_input
// Twist the light to change the value. When the current value changes,
// the green LED will flash, and the number that is currently being printed
// will be reset. Suppose you are at 2 and you want to go to 5. Rotate
// clockwise 3 green flashes, and you'll be there.
// The current value is printed through the rear leds.
// Get the result with get_input_digit.
extern void input_digit(unsigned int min_digit, unsigned int max_digit);

// grab the value that is currently selected (based on twist orientation)
extern unsigned int get_input_digit();

#endif // INPUT_DIGIT_H
Loading