Coupling the HMC5883L Compass with our color library turns the Wearable Wayfinder into a handy navigation device.
int get_color_from_angle(int angle){ Color cur_color=Color(0,0,0); cur_color.convert_hcl_to_rgb((float)angle/360,0.95,0.7); return cur_color.get_color_16bit(); }
This function translates from a degree ((0-360) that we got from the compass which represents our heading) and a color. Using the HSB color mode the above code maps each heading to a different hue. Then once we have read the heading from the compass (it is given in radians) we draw a ray and two orbiting circles rotated by the heading:
float headingDegrees = heading * 180/M_PI; draw_ray(64,80, headingDegrees, 40); draw_orbiter(64,80, headingDegrees, 22,6); draw_orbiter(64,80, headingDegrees, 32,3);
/* LucidTronix Wearable Wayfinder color compass * Rainbow colored wearable navigator * For instructions, details and schematic, See: * http://www.lucidtronix.com/tutorials/30 */#include#include // Core graphics library#include // Hardware-specific library#include #include #include #include #include #include #include // for leo:Adafruit_ST7735 tft = Adafruit_ST7735(SS, 9, 8);WearableWayfinder ww = WearableWayfinder(&tft);String directions[] = {"North", "North-west", "West", "South-west", "South", "South-east", "East", "North-east"};const int num_directions = 8;int old_direction_index = 0;float old_heading = 0;void setup(){ Wire.begin(); // Start the I2C interface. ww.initialize();}void loop(){ ww.draw_string(5, 3, "Compass", ww.stroke.color_16(), 2); float heading_degrees = ww.get_heading(); if(abs(heading_degrees - old_heading) > 3 ){ tft.fillRect(22, 38, 82, 82, ww.background.color_16()); } old_heading = heading_degrees; ww.draw_ray(64,80, heading_degrees, 40); ww.draw_orbiter(64,80, heading_degrees, 22,6); ww.draw_orbiter(64,80, heading_degrees, 32,3); int direction_index = map(heading_degrees, 0, 359, 0, num_directions); if(old_direction_index != direction_index){ tft.fillRect(2, 128, 108, 12, ww.background.color_16()); ww.draw_string(5, 128, directions[direction_index], ww.stroke.color_16(), 1); } old_direction_index = direction_index; ww.show_heading(10, 145); if ( digitalRead(ww.btn1_pin) == HIGH){ tft.fillScreen(ww.background.color_16()); }}
| Title | Description | # | Cost | Link | Picture |
| Wearable Wayfinder | An Arduino on steroids! Full color LCD screen, accelerometer, compass, and real time clock loaded onto a wearable gadget! | 1 | $69.95 | Link |
|
Comments: