/* * LM: Emulate magic eye tube * Requires Adafruit libraries supporting 1.5-inch 16-bit Color OLED display */ #include #include #include // #define DEBUG // Screen dimensions #define SCREEN_WIDTH 128 #define SCREEN_HEIGHT 128 // Change this to 96 for 1.27" OLED. // You can use any (4 or) 5 pins #define SCLK_PIN 2 #define MOSI_PIN 3 // AKA DIN #define DC_PIN 4 #define CS_PIN 5 #define RST_PIN 6 // Hardware /* #define SCLK_PIN 13 #define MOSI_PIN 11 #define DC_PIN 12 #define CS_PIN 10 #define RST_PIN 6 */ // Color definitions #define BLACK 0x0000 #define BLUE 0x001F #define RED 0xF800 #define GREEN 0x07E0 #define CYAN 0x07FF #define MAGENTA 0xF81F #define YELLOW 0xFFE0 #define WHITE 0xFFFF // Adafruit GREEN is 0x07E0 #define BRTGREEN 0x0380 // Simulate the lit part of the tube #define DIMGREEN 0x01A0 // Dimmer 0x200, Less dim 0x400 (still green) #define TESTCOLOR 0x0000 // Change value for testing // Option 1: use any pins but a little slower Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, CS_PIN, DC_PIN, MOSI_PIN, SCLK_PIN, RST_PIN); // Option 2: must use the hardware SPI pins // (for UNO thats sclk = 13 and sid = 11) and pin 10 must be // an output. This is much faster - also required if you want // to use the microSD card (see the image drawing example) // Adafruit_SSD1351 tft = Adafruit_SSD1351(SCREEN_WIDTH, SCREEN_HEIGHT, &SPI, CS_PIN, DC_PIN, RST_PIN); // Application-wide declarations follow: const boolean DOUBLE_WEDGE = true; // More realistic but slower (half-speed) const int TONE_OUT = 8; // DIO pin 8 - Random wedge demo 'sound effects' const int RADIO_PIN = A0; // Signal strength input const boolean RADIO_MODE = true; // If true, tracks signal on RADIO_PIN, else demo mode const boolean INVERT_S = true; // -> Stronger signal = narrower angle // Calibration const boolean RT_CAL = false; // If true sMin and sMAX auto-calibrate... Else, int sMin = 100; // Signal minimum (in units 0 to 1023 int sMax = 500; // Signal maximum (empirically determined) const int DAMPING_CONSTANT = 0; // Relative weight of recent signal readings // Value = 0 disables software damping const boolean TONE_DEMO = true; // Tone for demo random wedge (consumes cycles) const boolean MUSICAL_NOTES = false; // Substitute random notes for random frequency const int AMAX = 50; // Degrees const int XMAX = SCREEN_WIDTH; // Number of horizontal pixels const int YMAX = SCREEN_HEIGHT; // Number of vertical pixels const int X0 = XMAX/2; // Approximate middle const int Y0 = YMAX/2; const int R = Y0; // Radius of outer circle const int R_SMALL = 27; // Radius of inner circle const int R2 = 4096; // Squared radius of outer circle const int DEG = 90; // Degrees in quadrant const int MAX_DISPLAY_ANGLE = 45; // Less than or equal to maximum tabled angle // The following circle array is for testing. // QC stands for 'quarter circle' - Quadrant I // R=64 const int QC [R] = {64,64,64,64,64,64,64,63,63,63,63,63,63,62,62,62,62,61,61,61,60,60,60,59,59,58,58,58,57,57,56,55,55,54,54,53,52,51,51,50,49,48,47,46,46,44,43,42,41,40,39,37,36,34,33,31,29,27,25,22,19,16,11,0}; // R=27 (Center circle) const int SMQC [R_SMALL] = {27,27,27,27,27,26,26,26,25,25,25,24,24,23,22,22,21,20,19,18,17,16,14,12,10,7,0}; // Quadrant 1 pixel array, presently 2 to 50 degrees // Subscript order: angle in degrees, delta x, delta y_min, delta y_max const int DIMV = 754; const int PROGMEM V [DIMV] [4] = { // {angle, x, min y, max y} {2,1,43,63}, {3,1,29,42}, {3,2,48,63}, {4,1,27,28}, {4,2,36,47}, {4,3,50,63}, {5,2,29,35}, {5,3,40,49}, {5,4,51,63}, {5,5,63,63}, {6,2,27,28}, {6,3,33,39}, {6,4,43,50}, {6,5,52,62}, {6,6,62,63}, {7,3,29,32}, {7,4,37,42}, {7,5,45,51}, {7,6,53,61}, {7,7,61,63}, {8,3,27,28}, {8,4,32,36}, {8,5,39,44}, {8,6,46,52}, {8,7,53,60}, {8,8,60,63}, {9,4,28,31}, {9,5,35,38}, {9,6,41,45}, {9,7,47,52}, {9,8,54,59}, {9,9,60,63}, {10,4,27,27}, {10,5,31,34}, {10,6,37,40}, {10,7,43,46}, {10,8,48,53}, {10,9,54,59}, {10,10,60,63}, {11,5,28,30}, {11,6,33,36}, {11,7,39,42}, {11,8,44,47}, {11,9,49,53}, {11,10,54,59}, {11,11,59,63}, {12,5,27,27}, {12,6,31,32}, {12,7,35,38}, {12,8,40,43}, {12,9,45,48}, {12,10,49,53}, {12,11,54,58}, {12,12,59,62}, {13,6,28,30}, {13,7,32,34}, {13,8,37,39}, {13,9,41,44}, {13,10,45,48}, {13,11,50,53}, {13,12,54,58}, {13,13,58,62}, {14,6,27,27}, {14,7,30,31}, {14,8,34,36}, {14,9,38,40}, {14,10,42,44}, {14,11,46,49}, {14,12,50,53}, {14,13,54,57}, {14,14,58,62}, {14,15,62,62}, {15,7,28,29}, {15,8,32,33}, {15,9,35,37}, {15,10,39,41}, {15,11,43,45}, {15,12,47,49}, {15,13,50,53}, {15,14,54,57}, {15,15,58,61}, {16,7,27,27}, {16,8,30,31}, {16,9,33,34}, {16,10,37,38}, {16,11,40,42}, {16,12,44,46}, {16,13,47,49}, {16,14,51,53}, {16,15,54,57}, {16,16,58,61}, {16,17,61,61}, {17,8,28,29}, {17,9,31,32}, {17,10,34,36}, {17,11,38,39}, {17,12,41,43}, {17,13,44,46}, {17,14,47,50}, {17,15,51,53}, {17,16,54,57}, {17,17,57,60}, {17,18,61,61}, {18,8,26,27}, {18,9,29,30}, {18,10,32,33}, {18,11,35,37}, {18,12,38,40}, {18,13,42,43}, {18,14,45,46}, {18,15,48,50}, {18,16,51,53}, {18,17,54,56}, {18,18,57,60}, {18,19,60,61}, {19,9,28,28}, {19,10,30,31}, {19,11,33,34}, {19,12,36,37}, {19,13,39,41}, {19,14,42,44}, {19,15,45,47}, {19,16,48,50}, {19,17,51,53}, {19,18,54,56}, {19,19,57,59}, {19,20,60,60}, {20,9,26,27}, {20,10,29,29}, {20,11,32,32}, {20,12,34,35}, {20,13,37,38}, {20,14,40,41}, {20,15,43,44}, {20,16,45,47}, {20,17,48,50}, {20,18,51,53}, {20,19,54,56}, {20,20,56,59}, {20,21,59,60}, {21,10,27,28}, {21,11,30,31}, {21,12,33,33}, {21,13,35,36}, {21,14,38,39}, {21,15,40,42}, {21,16,43,44}, {21,17,46,47}, {21,18,48,50}, {21,19,51,53}, {21,20,53,55}, {21,21,56,58}, {21,22,59,60}, {22,10,26,26}, {22,11,28,29}, {22,12,31,32}, {22,13,33,34}, {22,14,36,37}, {22,15,38,39}, {22,16,41,42}, {22,17,43,45}, {22,18,46,47}, {22,19,48,50}, {22,20,51,52}, {22,21,53,55}, {22,22,56,58}, {22,23,58,59}, {23,11,27,27}, {23,12,29,30}, {23,13,32,32}, {23,14,34,35}, {23,15,37,37}, {23,16,39,40}, {23,17,41,42}, {23,18,44,45}, {23,19,46,47}, {23,20,48,50}, {23,21,51,52}, {23,22,53,55}, {23,23,55,57}, {23,24,58,59}, {24,11,26,26}, {24,12,28,28}, {24,13,30,31}, {24,14,33,33}, {24,15,35,36}, {24,16,37,38}, {24,17,39,40}, {24,18,42,43}, {24,19,44,45}, {24,20,46,47}, {24,21,48,50}, {24,22,51,52}, {24,23,53,54}, {24,24,55,57}, {24,25,57,58}, {25,11,25,25}, {25,12,27,27}, {25,13,29,29}, {25,14,31,32}, {25,15,33,34}, {25,16,35,36}, {25,17,38,38}, {25,18,40,41}, {25,19,42,43}, {25,20,44,45}, {25,21,46,47}, {25,22,48,50}, {25,23,50,52}, {25,24,53,54}, {25,25,55,56}, {25,26,57,58}, {26,12,26,26}, {26,13,28,28}, {26,14,30,30}, {26,15,32,32}, {26,16,34,34}, {26,17,36,37}, {26,18,38,39}, {26,19,40,41}, {26,20,42,43}, {26,21,44,45}, {26,22,46,47}, {26,23,48,49}, {26,24,50,52}, {26,25,52,54}, {26,26,54,56}, {26,27,56,58}, {27,12,25,25}, {27,13,26,27}, {27,14,28,29}, {27,15,30,31}, {27,16,32,33}, {27,17,34,35}, {27,18,36,37}, {27,19,38,39}, {27,20,40,41}, {27,21,42,43}, {27,22,44,45}, {27,23,46,47}, {27,24,48,49}, {27,25,50,51}, {27,26,52,53}, {27,27,54,55}, {27,28,56,57}, {28,13,25,25}, {28,14,27,27}, {28,15,29,29}, {28,16,31,31}, {28,17,33,33}, {28,18,35,35}, {28,19,37,37}, {28,20,39,39}, {28,21,40,41}, {28,22,42,43}, {28,23,44,45}, {28,24,46,47}, {28,25,48,49}, {28,26,50,51}, {28,27,52,53}, {28,28,54,55}, {28,29,55,57}, {29,13,24,24}, {29,14,26,26}, {29,15,28,28}, {29,16,30,30}, {29,17,32,32}, {29,18,33,34}, {29,19,35,36}, {29,20,37,38}, {29,21,39,39}, {29,22,41,41}, {29,23,42,43}, {29,24,44,45}, {29,25,46,47}, {29,26,48,49}, {29,27,50,51}, {29,28,51,53}, {29,29,53,54}, {29,30,55,56}, {30,14,25,25}, {30,15,27,27}, {30,16,29,29}, {30,17,30,31}, {30,18,32,32}, {30,19,34,34}, {30,20,36,36}, {30,21,37,38}, {30,22,39,40}, {30,23,41,41}, {30,24,42,43}, {30,25,44,45}, {30,26,46,47}, {30,27,48,49}, {30,28,49,50}, {30,29,51,52}, {30,30,53,54}, {30,31,55,55}, {31,14,24,24}, {31,15,26,26}, {31,16,27,28}, {31,17,29,29}, {31,18,31,31}, {31,19,32,33}, {31,20,34,35}, {31,21,36,36}, {31,22,37,38}, {31,23,39,40}, {31,24,41,41}, {31,25,42,43}, {31,26,44,45}, {31,27,46,47}, {31,28,47,48}, {31,29,49,50}, {31,30,51,52}, {31,31,52,54}, {31,32,54,55}, {32,15,25,25}, {32,16,26,26}, {32,17,28,28}, {32,18,30,30}, {32,19,31,31}, {32,20,33,33}, {32,21,34,35}, {32,22,36,36}, {32,23,38,38}, {32,24,39,40}, {32,25,41,41}, {32,26,42,43}, {32,27,44,45}, {32,28,46,46}, {32,29,47,48}, {32,30,49,50}, {32,31,50,51}, {32,32,52,53}, {32,33,54,54}, {33,15,24,24}, {33,16,25,25}, {33,17,27,27}, {33,18,28,29}, {33,19,30,30}, {33,20,32,32}, {33,21,33,33}, {33,22,35,35}, {33,23,36,37}, {33,24,38,38}, {33,25,39,40}, {33,26,41,41}, {33,27,42,43}, {33,28,44,45}, {33,29,45,46}, {33,30,47,48}, {33,31,49,49}, {33,32,50,51}, {33,33,52,53}, {33,34,53,54}, {34,15,23,23}, {34,16,24,24}, {34,17,26,26}, {34,18,27,27}, {34,19,29,29}, {34,20,30,31}, {34,21,32,32}, {34,22,33,34}, {34,23,35,35}, {34,24,36,37}, {34,25,38,38}, {34,26,39,40}, {34,27,41,41}, {34,28,42,43}, {34,29,44,44}, {34,30,45,46}, {34,31,47,48}, {34,32,48,49}, {34,33,50,51}, {34,34,51,52}, {34,35,53,53}, {35,17,25,25}, {35,18,26,26}, {35,19,28,28}, {35,20,29,29}, {35,21,31,31}, {35,22,32,32}, {35,23,34,34}, {35,24,35,35}, {35,25,36,37}, {35,26,38,38}, {35,27,39,40}, {35,28,41,41}, {35,29,42,43}, {35,30,44,44}, {35,31,45,46}, {35,32,46,47}, {35,33,48,49}, {35,34,49,50}, {35,35,51,52}, {35,36,52,52}, {36,16,23,23}, {36,17,24,24}, {36,18,25,25}, {36,19,27,27}, {36,20,28,28}, {36,21,30,30}, {36,22,31,31}, {36,23,32,33}, {36,24,34,34}, {36,25,35,35}, {36,26,36,37}, {36,27,38,38}, {36,28,39,40}, {36,29,41,41}, {36,30,42,43}, {36,31,43,44}, {36,32,45,45}, {36,33,46,47}, {36,34,47,48}, {36,35,49,50}, {36,36,50,51}, {36,37,52,52}, {37,16,22,22}, {37,17,23,23}, {37,19,26,26}, {37,20,27,27}, {37,21,29,29}, {37,22,30,30}, {37,23,31,31}, {37,24,33,33}, {37,25,34,34}, {37,26,35,35}, {37,27,36,37}, {37,28,38,38}, {37,29,39,40}, {37,30,40,41}, {37,31,42,42}, {37,32,43,44}, {37,33,44,45}, {37,34,46,46}, {37,35,47,48}, {37,36,48,49}, {37,37,50,51}, {37,38,51,51}, {38,17,22,22}, {38,18,24,24}, {38,19,25,25}, {38,20,26,26}, {38,21,28,28}, {38,22,29,29}, {38,23,30,30}, {38,24,31,32}, {38,25,33,33}, {38,26,34,34}, {38,27,35,35}, {38,28,36,37}, {38,29,38,38}, {38,30,39,39}, {38,31,40,41}, {38,32,42,42}, {38,33,43,43}, {38,34,44,45}, {38,35,45,46}, {38,36,47,47}, {38,37,48,49}, {38,38,49,50}, {39,18,23,23}, {39,19,24,24}, {39,20,25,25}, {39,21,27,27}, {39,22,28,28}, {39,23,29,29}, {39,24,30,30}, {39,25,31,32}, {39,26,33,33}, {39,27,34,34}, {39,28,35,35}, {39,29,36,37}, {39,30,38,38}, {39,31,39,39}, {39,32,40,41}, {39,33,41,42}, {39,34,43,43}, {39,35,44,44}, {39,36,45,46}, {39,37,46,47}, {39,38,48,48}, {39,39,49,50}, {40,17,21,21}, {40,18,22,22}, {40,19,23,23}, {40,20,24,24}, {40,21,26,26}, {40,22,27,27}, {40,23,28,28}, {40,24,29,29}, {40,25,30,30}, {40,26,32,32}, {40,27,33,33}, {40,28,34,34}, {40,29,35,35}, {40,30,36,37}, {40,31,38,38}, {40,32,39,39}, {40,33,40,40}, {40,34,41,42}, {40,35,42,43}, {40,36,43,44}, {40,37,45,45}, {40,38,46,47}, {40,39,47,48}, {40,40,48,49}, {40,41,49,49}, {41,18,21,21}, {41,19,22,22}, {41,21,25,25}, {41,22,26,26}, {41,23,27,27}, {41,24,28,28}, {41,25,29,29}, {41,26,30,31}, {41,27,32,32}, {41,28,33,33}, {41,29,34,34}, {41,30,35,35}, {41,31,36,37}, {41,32,37,38}, {41,33,39,39}, {41,34,40,40}, {41,35,41,41}, {41,36,42,42}, {41,37,43,44}, {41,38,44,45}, {41,39,45,46}, {41,40,47,47}, {41,41,48,48}, {42,20,23,23}, {42,21,24,24}, {42,22,25,25}, {42,23,26,26}, {42,24,27,27}, {42,25,28,28}, {42,26,29,29}, {42,27,31,31}, {42,28,32,32}, {42,29,33,33}, {42,30,34,34}, {42,31,35,35}, {42,32,36,36}, {42,33,37,38}, {42,34,38,39}, {42,35,39,40}, {42,36,41,41}, {42,37,42,42}, {42,38,43,43}, {42,39,44,44}, {42,40,45,46}, {42,41,46,47}, {42,42,47,48}, {43,19,21,21}, {43,20,22,22}, {43,21,23,23}, {43,22,24,24}, {43,23,25,25}, {43,24,26,26}, {43,25,27,27}, {43,26,28,28}, {43,27,29,30}, {43,28,31,31}, {43,29,32,32}, {43,30,33,33}, {43,31,34,34}, {43,32,35,35}, {43,33,36,36}, {43,34,37,37}, {43,35,38,38}, {43,36,39,40}, {43,37,40,41}, {43,38,41,42}, {43,39,42,43}, {43,40,43,44}, {43,41,45,45}, {43,42,46,46}, {43,43,47,47}, {44,19,20,20}, {44,20,21,21}, {44,21,22,22}, {44,22,23,23}, {44,23,24,24}, {44,24,25,25}, {44,25,26,26}, {44,26,27,27}, {44,27,28,28}, {44,28,30,30}, {44,29,31,31}, {44,30,32,32}, {44,31,33,33}, {44,32,34,34}, {44,33,35,35}, {44,34,36,36}, {44,35,37,37}, {44,36,38,38}, {44,37,39,39}, {44,38,40,40}, {44,39,41,41}, {44,40,42,42}, {44,41,43,44}, {44,42,44,45}, {44,43,45,46}, {44,44,46,46}, {45,20,20,20}, {45,21,21,21}, {45,22,22,22}, {45,23,23,23}, {45,24,24,24}, {45,25,25,25}, {45,26,26,26}, {45,27,27,27}, {45,28,28,29}, {45,29,29,30}, {45,30,30,31}, {45,31,31,32}, {45,32,32,33}, {45,33,33,34}, {45,34,34,35}, {45,35,35,36}, {45,36,36,37}, {45,37,37,38}, {45,38,38,39}, {45,39,39,40}, {45,40,40,41}, {45,41,41,42}, {45,42,42,43}, {45,43,43,44}, {45,44,44,45}, {45,45,45,45}, {46,29,28,28}, {46,30,29,29}, {46,31,30,30}, {46,32,31,31}, {46,33,32,32}, {46,34,33,33}, {46,35,34,34}, {46,36,35,35}, {46,37,36,36}, {46,38,37,37}, {46,39,38,38}, {46,40,39,39}, {46,41,40,40}, {46,42,41,41}, {46,43,42,42}, {46,44,43,43}, {46,45,44,44}, {47,20,19,19}, {47,21,20,20}, {47,22,21,21}, {47,23,22,22}, {47,24,23,23}, {47,25,24,24}, {47,26,25,25}, {47,27,26,26}, {47,28,27,27}, {47,30,28,28}, {47,31,29,29}, {47,32,30,30}, {47,33,31,31}, {47,34,32,32}, {47,35,33,33}, {47,36,34,34}, {47,37,35,35}, {47,38,36,36}, {47,39,37,37}, {47,40,38,38}, {47,41,39,39}, {47,42,40,40}, {47,43,41,41}, {47,44,41,42}, {47,45,42,43}, {47,46,43,44}, {48,21,19,19}, {48,22,20,20}, {48,23,21,21}, {48,24,22,22}, {48,25,23,23}, {48,26,24,24}, {48,27,25,25}, {48,28,26,26}, {48,29,27,27}, {48,30,27,27}, {48,31,28,28}, {48,32,29,29}, {48,33,30,30}, {48,34,31,31}, {48,35,32,32}, {48,36,33,33}, {48,37,34,34}, {48,38,35,35}, {48,39,36,36}, {48,40,36,37}, {48,41,37,38}, {48,42,38,39}, {48,43,39,40}, {48,44,40,40}, {48,45,41,41}, {48,46,42,42}, {48,47,43,43}, {49,23,20,20}, {49,24,21,21}, {49,25,22,22}, {49,26,23,23}, {49,27,24,24}, {49,28,25,25}, {49,29,26,26}, {49,31,27,27}, {49,32,28,28}, {49,33,29,29}, {49,34,30,30}, {49,35,31,31}, {49,36,32,32}, {49,37,33,33}, {49,38,33,34}, {49,39,34,35}, {49,40,35,35}, {49,41,36,36}, {49,42,37,37}, {49,43,38,38}, {49,44,39,39}, {49,45,40,40}, {49,46,40,41}, {49,47,41,42}, {49,48,42,42}, {50,21,18,18}, {50,22,19,19}, {50,25,21,21}, {50,26,22,22}, {50,27,23,23}, {50,28,24,24}, {50,29,25,25}, {50,30,26,26}, {50,31,26,26}, {50,32,27,27}, {50,33,28,28}, {50,34,29,29}, {50,35,30,30}, {50,36,31,31}, {50,37,31,32}, {50,38,32,32}, {50,39,33,33}, {50,40,34,34}, {50,41,35,35}, {50,42,36,36}, {50,43,37,37}, {50,44,37,38}, {50,45,38,39}, {50,46,39,39}, {50,47,40,40}, {50,48,41,41} }; const int VNDX[AMAX-1] = {0, 1, 3, 6, 10, 15, 20, 26, 32, 39, 46, 54, 62, 72, 81, 92, 103, 115, 127, 140, 153, 167, 181, 196, 212, 228, 245, 262, 280, 298, 317, 336, 356, 377, 397, 419, 441, 463, 485, 510, 533, 556, 581, 607, 633, 650, 676, 703, 728}; int lastOpening = 0; // Last width before changing in response to analog data long sDamping = AMAX / 2; // For use in damping received signal strength // Substitute notes for frequencies in correlated tone demo // Two octaves + one half-step (for the convenient 8/15 calculation) // * Slower, because average frequency is lower in the note range! const int TONES = 25; const int NOTES[] = {262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622, 659, 740, 784, 831, 880, 932, 988, 1047, 1108}; void setup() { #ifdef DEBUG Serial.begin(9600); #endif // Not sure if radio signal pin should be pulled up pinMode(RADIO_PIN, INPUT); if (RADIO_MODE && RT_CAL) { sMin = 1023; sMax = 0; } pinMode(TONE_OUT, OUTPUT); tft.begin(); tft.fillScreen(BLACK); delay(1000); tft.fillCircle(X0, Y0, R-1, BRTGREEN); tft.fillCircle(X0, Y0, R_SMALL, DIMGREEN); randomSeed(analogRead(0)); if (!RADIO_MODE) { testV(DIMGREEN); delay(2000); testV(BRTGREEN); delay(2000); } initMidline(DIMGREEN); } void loop() { int to; int from = lastOpening; if (RADIO_MODE) to = signalStrength(); else { to = random(MAX_DISPLAY_ANGLE); int freq; if (TONE_DEMO) { if (MUSICAL_NOTES) freq = NOTES[TONES - (to*8/15)- 1]; else freq = 1200-(to*20); tone(TONE_OUT, freq); } } #ifdef DEBUG Serial.println("to = " + String(to) + ", from = " + String(from)); #endif if (to > from) // Shrink drawV(from, to, DIMGREEN); else if (to < from) // Expand drawV(from, to, BRTGREEN); lastOpening = to; } int fetch(int i, int j) { //Placeholder return pgm_read_word_near(V[i] + j); } void drawV(int from, int to, uint16_t color) { // parameters 'from' and 'to' are degrees from -= 2; // Convert degrees to VNDX subscript to -= 2; if (from < 0) from = 0; // Index to angle cannot be negative, etc. if (to < 0) to = 0; if (from > (AMAX-1)) from = AMAX-1; if (to > (AMAX-1)) to = AMAX-1; int phi, v_from, v_to, x, y, y1, y2, h; if (from == to) return; else if (from < to) { // Expanding wedge v_from = VNDX[from]; // Starting point in large data array if (to == (AMAX-1)) // v_to = DIMV; v_to = VNDX[to]; // For startup before S-meter calibration else v_to = VNDX[to+1]; // Stopping point in large data array for (int i=v_from; iv_to; i--) { x = fetch(i, 1); // delta x (offset from X0) y1 = fetch(i, 2); // delta y (smallest y for specified x) y2 = fetch(i, 3); // delta y (largest y for specified x) h = y2 - y1 + 1; // Not used in drawPixel - For drawFastVLine tft.drawFastVLine(X0+x, Y0-y2, h, color); tft.drawFastVLine(X0-x, Y0-y2, h, color); if (DOUBLE_WEDGE) { // Bottom wedge (Reduces speed to 1/2) tft.drawFastVLine(X0+x, Y0+y1, h, color); tft.drawFastVLine(X0-x, Y0+y1, h, color); } // Alternatively tft.drawPixel loop ... } // End for (i...) } // End else // Contracting wedge } int signalStrength() { int s = analogRead(RADIO_PIN); if (RT_CAL) { if (s < sMin) sMin = s; else if (s > sMax) sMax = s; } else { if (s < sMin) s = sMin; else if (s > sMax) s = sMax; } #ifdef DEBUG Serial.println("s = " + String(s) + ", sMin = " + String(sMin) + ", sMax= " + String(sMax)); #endif // Convert to angle long tmp; if ((sMax - sMin) > 0) tmp = (long) (s - sMin) * (long) MAX_DISPLAY_ANGLE / (long) (sMax - sMin); else tmp = MAX_DISPLAY_ANGLE - 1; #ifdef DEBUG Serial.println("Angle = " + String(tmp)); #endif if (INVERT_S) tmp = MAX_DISPLAY_ANGLE - tmp; return dampen(tmp); } int dampen(long sAngle) { if (DAMPING_CONSTANT == 0) return sAngle; sDamping = (sDamping * DAMPING_CONSTANT + sAngle) / (DAMPING_CONSTANT + 1); #ifdef DEBUG Serial.println("Dampened sAngle = " + String(sDamping)); #endif return (int) sDamping; } // * Below will be removed when testing is complete void initMidline(uint16_t color) { int from = Y0; if (DOUBLE_WEDGE) from = YMAX; for (int y=from; y>=0; y--) { tft.drawPixel(X0-1, y, color); tft.drawPixel(X0, y, color); tft.drawPixel(X0+1, y, color); } } void testV(uint16_t color) { // Ascertain if V can be placed in variable storage int phi, x, y, y1,y2; // Finally a clean wedge for (int i=0; i