1 #include <LiquidCrystal.h>
7 // Update this _every_ time a change in datastructures that
8 // can/will ber written to EEPROM is done. EEPROM data is
9 // read/written torectly into/from the data structures using
10 // pointers, so every time a data-set change occurs, the EEPROM
11 // format changes as well..
12 #define EEPROM_VERSION 7
14 // Some data is stored in fixed locations, e.g.:
15 // * The EEPROM version number for the stored data (loc 0)
16 // * The selected model configuration number (loc 1)
17 // * (add any other fixed-loc's here for doc-purpose)
18 // This means that any pointer-math-operations need a BASE
19 // adress to start calc'ing from. This is defined as:
20 #define EE_BASE_ADDR 10
22 // Having to repeat tedious base-address-calculations for the
23 // start of model data should be unnessecary. Plus, updating
24 // what data is stored before the models will mean that each
25 // of those calculations must be updated. A better approach is
26 // to define the calculation in a define!
27 // NOTE: If new data is added in front of the model data,
28 // this define must be updated!
29 #define EE_MDL_BASE_ADDR (EE_BASE_ADDR+(sizeof(input_cal_t)+ 10))
31 // Just as a safety-precaution, update/change this if a chip with
32 // a different internal EEPROM size is used. Atmega328p has 1024 bytes.
33 #define INT_EEPROM_SIZE 1024
35 #define MAX_MODELS 4 // Nice and random number..
38 // --------------- ADC related stuffs.... --------------------
40 struct input_cal_t // Struct type for input calibration values
44 int center[MAX_INPUTS];
46 input_cal_t input_cal;
50 int channels; // How many channels should PPM generate for this model ...
51 float stick[8]; // The (potentially recalc'ed) value of stick/input channel.
54 int dr[8]; // The Dual-rate array uses magic numbers :P
55 /* dr[0] = Input channel #1 of 2 for D/R switch #1. 0 means off, 1-4 valid values.
56 dr[1] = Input channel #2 of 2 for D/R switch #1. 0 means off, 1-4 valid values.
57 dr[2] = Input channel #1 of 2 for D/R switch #2. 0 means off, 1-4 valid values.
58 dr[3] = Input channel #2 of 2 for D/R switch #2. 0 means off, 1-4 valid values.
59 dr[4] = D/R value for switch # 1 LOW(off). Value -100 to 100 in steps of 5.
60 dr[5] = D/R value for switch # 1 HIGH(on). Value -100 to 100 in steps of 5.
61 dr[6] = D/R value for switch # 1 LOW(off). Value -100 to 100 in steps of 5.
62 dr[7] = D/R value for switch # 1 HIGH(on). Value -100 to 100 in steps of 5.
65 volatile model_t model;
66 unsigned char current_model; // Using uchar to spend a single byte of mem..
68 // ----------------- Display related stuffs --------------------
69 LiquidCrystal lcd( 12, 11, 10, 6, 7, 8, 9);
70 // Parameters are: rs, rw, enable, d4, d5, d6, d7 pin numbers.
72 // ----------------- PPM related stuffs ------------------------
73 // The PPM generation is handled by Timer0 interrupts, and needs
74 // all modifiable variables to be global and volatile...
76 volatile long sum = 0; // Frame-time spent so far
77 volatile int cchannel = 0; // Current channnel
78 volatile bool do_channel = true; // Is next operation a channel or a separator
81 // All time values in usecs
83 // The timing here (and/or in the ISR) needs to be tweaked to provide valid
84 // RC PPM signals accepted by standard RC RX'es and the Microcopter...
86 #define framelength 21000 // Max length of frame
87 #define seplength 300 // Lenght of a channel separator
88 #define chmax 1550 // Max lenght of channel pulse
89 #define chmin 620 // Min length of channel
90 #define chwidht (chmax - chmin)// Useable time of channel pulse
92 // ----------------- Menu/IU related stuffs --------------------
94 // Keys/buttons/switches for UI use, including dual-rate/expo
95 // are digital inputs connected to a 4051 multiplexer, giving
96 // 8 inputs on a single input pin.
106 // Voltage sense pin is connected to a 1/3'd voltage divider.
107 #define BATTERY_CONV (10 * 3 * (5.0f/1024.0f))
108 #define BATTERY_LOW 92
123 EXPOS, // Some radios have "drawn curves", i.e. loopup tables stored in external EEPROM ...
131 boolean prev_keys[8];
135 // The display/UI is handled only when more
136 // than UI_INTERVAL milliecs has passed since last...
137 #define UI_INTERVAL 250
138 unsigned long last = 0;
148 // ----------------- DEBUG-STUFF --------------------
149 unsigned long prev_loop_time;
150 unsigned long avg_loop_time;
154 // ---------- CODE! -----------------------------------
156 // ---------- Arduino SETUP code ----------------------
158 pinMode(13, OUTPUT); // led
160 pinMode(2, OUTPUT); // s0
161 pinMode(3, OUTPUT); // s1
162 pinMode(4, OUTPUT); // s2
163 pinMode(5, OUTPUT); // e
166 lcd.print("Starting....");
169 Serial.println("Starting....");
175 displaystate = VALUES;
177 // Arduino believes all pins on Port C are Analog.
178 // In reality they are tri-purpose; ADC, Digital, Digital Interrupts
179 // Unfortunately the interrupt mode is unusable in this scenario, but digital I/O works :P
181 digitalWrite(A2, HIGH);
186 // Debugging: how long does the main loop take on avg...
192 // Initializing the stopwatch timer/clock values...
193 clock_timer = (clock_timer_t){0, 0, 0, false};
195 pinMode(A5, OUTPUT); // PPM output pin
197 set_timer( seplength );
198 Timer1.initialize(framelength);
199 Timer1.attachInterrupt(ISR_timer);
203 void model_defaults( void )
205 // This function provides default values for model data
206 // that is not a result of stick input, or in other words:
207 // provides defautls for all user-configurable model options.
209 // Remember to update this when a new option/element is added
210 // to the model_t struct (preferably before implementing the
211 // menu code that sets those options ...)
213 // This is used when a user wants a new, blank model, a reset
214 // of a configured model, and (most important) when EEPROM
215 // data format changes.
216 // NOTE: This means that stored model conficuration is reset
217 // to defaults when the EEPROM version/format changes.
219 model.rev[0] = model.rev[1] = model.rev[2] = model.rev[3] =
220 model.rev[4] = model.rev[5] = model.rev[6] = model.rev[7] = false;
221 model.dr[0] = model.dr[1] = model.dr[2] = model.dr[3] = 0;
222 model.dr[4] = model.dr[5] = model.dr[6] = model.dr[7] = 100;
226 // ---------- Arduino main loop -----------------------
229 // Determine if the UI needs to run...
231 if ( millis() - last > UI_INTERVAL ) {
239 // Wasting a full I/O pin on battery status monitoring!
240 battery_val = analogRead(1) * BATTERY_CONV;
241 if ( battery_val < BATTERY_LOW ) {
242 digitalWrite(13, 1); // Simulate alarm :P
243 displaystate = BATTERY;
250 if ( displaystate != MENU )
252 // Debugging: how long does the main loop take on avg,
253 // when not handling the UI...
255 avg_loop_time = ( t - prev_loop_time + avg_loop_time ) / 2;
259 // Whoa! Slow down partner! Let everything settle down before proceeding.
263 // ----- Simple support functions used by more complex functions ----
265 void set_ppm_output( bool state )
267 digitalWrite(A5, state); // Hard coded PPM output
270 void set_timer(long time)
272 Timer1.detachInterrupt();
273 Timer1.attachInterrupt(ISR_timer, time);
276 boolean check_key( int key)
278 return ( !keys[key] && prev_keys[key] );
281 void mplx_select(int pin)
284 delayMicroseconds(24);
286 digitalWrite(2, bitRead(pin,0)); // Arduino alias for non-modifying bitshift operation
287 digitalWrite(3, bitRead(pin,1)); // us used to extract individual bits from the int (0..7)
288 digitalWrite(4, bitRead(pin,2)); // Select the appropriate input by setting s1,s2,s3 and e
289 digitalWrite(5, 0); // on the 4051 multiplexer.
291 // May need to slow the following read down to be able to
292 // get fully reliable values from the 4051 multiplex.
293 delayMicroseconds(24);
297 // ----- "Complex" functions follow ---------------------------------
302 int num_calibrations = 200;
305 lcd.print("Move controls to");
307 lcd.print("their extremes..");
308 Serial.print("Calibration. Move all controls to their extremes.");
310 for (i=0; i<MAX_INPUTS; i++) {
311 input_cal.min[i] = 1024;
312 input_cal.center[i] = 512;
313 input_cal.max[i] = 0;
316 while ( num_calibrations-- )
318 for (i=0; i<MAX_INPUTS; i++) {
320 adc_in = analogRead(0);
322 // Naive min/max calibration
323 if ( adc_in < input_cal.min[i] ) {
324 input_cal.min[i] = adc_in;
326 if ( adc_in > input_cal.max[i] ) {
327 input_cal.max[i] = adc_in;
333 // TODO: WILL need to do center-point calibration after min-max...
336 lcd.print("Saving to EEPROM");
338 lcd.setCursor(0 , 1);
339 lcd.print("Done calibrating");
341 Serial.print("Done calibrating");
345 void write_calibration(void)
351 // Set p to be a pointer to the start of the input calibration struct.
352 p = (const byte*)(const void*)&input_cal;
354 // Iterate through the bytes of the struct...
355 for (i = 0; i < sizeof(input_cal_t); i++)
357 // Get a byte of data from the struct...
358 v = (unsigned char) *p;
359 // write it to EEPROM
360 EEPROM.write( EE_BASE_ADDR + i, v);
361 // and move the pointer to the next byte in the struct.
366 void read_settings(void)
373 if ( v != EEPROM_VERSION )
375 // All models have been reset. Set the current model to 0
377 EEPROM.write(1, current_model);
381 // The following does not yet work...
382 for ( i = 0; i < MAX_MODELS; i++)
383 write_model_settings(i);
386 // After saving calibration data and model defaults,
387 // update the saved version-identifier to the current ver.
388 EEPROM.write(0, EEPROM_VERSION);
391 // Read calibration values from EEPROM.
392 // This uses simple pointer-arithmetic and byte-by-byte
393 // to put bytes read from EEPROM to the data-struct.
394 p = (byte*)(void*)&input_cal;
395 for (i = 0; i < sizeof(input_cal_t); i++)
396 *p++ = EEPROM.read( EE_BASE_ADDR + i);
398 // Get the previously selected model from EEPROM.
399 current_model = EEPROM.read(1);
400 read_model_settings( current_model );
403 void read_model_settings(unsigned char mod_no)
410 // Calculate the EEPROM start adress for the given model (mod_no)
411 model_address = EE_MDL_BASE_ADDR + (mod_no * sizeof(model_t));
413 // Do not try to write the model to EEPROM if it won't fit.
414 if ( INT_EEPROM_SIZE < (model_address + sizeof(model_t)) )
417 lcd.print("Aborting READ");
418 lcd.setCursor(0 , 1);
419 lcd.print("Invalid location");
425 lcd.print("Reading model ");
426 lcd.print( (int)mod_no );
428 // Pointer to the start of the model_t data struct,
429 // used for byte-by-byte reading of data...
430 p = (byte*)(void*)&model;
431 for (i = 0; i < sizeof(model_t); i++)
432 *p++ = EEPROM.read( model_address++ );
436 lcd.setCursor(0 , 1);
437 lcd.print("... Loaded.");
441 void write_model_settings(unsigned char mod_no)
448 // Calculate the EEPROM start adress for the given model (mod_no)
449 model_address = EE_MDL_BASE_ADDR + (mod_no * sizeof(model_t));
451 // Do not try to write the model to EEPROM if it won't fit.
452 if ( INT_EEPROM_SIZE < (model_address + sizeof(model_t)) )
455 lcd.print("Aborting SAVE");
456 lcd.setCursor(0 , 1);
457 lcd.print("No room for data");
463 lcd.print("Saving model ");
464 lcd.print( (int)mod_no);
466 // Pointer to the start of the model_t data struct,
467 // used for byte-by-byte reading of data...
468 p = (byte*)(void*)&model;
470 // Write/serialize the model data struct to EEPROM...
471 for (i = 0; i < sizeof(model_t); i++)
472 EEPROM.write( model_address++, *p++);
474 lcd.setCursor(0 , 1);
475 lcd.print(".. done saving.");
479 void serial_dump_model ( void )
483 // Calculate the EEPROM start adress for the given model (mod_no)
484 model_address = EE_MDL_BASE_ADDR + (current_model * sizeof(model_t));
485 Serial.print("Current model: ");
486 Serial.println( (int)current_model );
487 Serial.print("Models base addr: ");
488 Serial.println( EE_MDL_BASE_ADDR );
489 Serial.print("Model no: ");
490 Serial.println( current_model, 10 );
491 Serial.print("Size of struct: ");
492 Serial.println( sizeof( model_t) );
493 Serial.print("Model address: ");
494 Serial.println( model_address );
495 Serial.print("End of model: ");
496 Serial.println( model_address + sizeof(model_t) );
500 Serial.print("Channel reversions: ");
501 for ( i = 0; i<8; i++)
505 Serial.print(model.rev[i], 10);
510 Serial.print("DR1 inp 0: ");
511 Serial.println(model.dr[0]);
512 Serial.print("DR1 inp 1: ");
513 Serial.println(model.dr[1]);
514 Serial.print("DR1 LO val: ");
515 Serial.println(model.dr[4]);
516 Serial.print("DR1 HI val: ");
517 Serial.println(model.dr[5]);
518 Serial.print("DR2 inp 0: ");
519 Serial.println(model.dr[2]);
520 Serial.print("DR2 inp 1: ");
521 Serial.println(model.dr[3]);
522 Serial.print("DR2 LO val: ");
523 Serial.println(model.dr[6]);
524 Serial.print("DR2 HI val: ");
525 Serial.println(model.dr[7]);
527 for (i=0; i<MAX_INPUTS; i++) {
528 Serial.print("Input #");
530 Serial.print(" pct: ");
531 Serial.print(model.stick[i]);
532 Serial.print(" min: ");
533 Serial.print(input_cal.min[i]);
534 Serial.print(" max: ");
535 Serial.print(input_cal.max[i]);
540 void scan_keys ( void )
544 // To get more inputs, another 4051 analog multiplexer is used,
545 // but this time it is used for digital inputs. 8 digital inputs
546 // on one input line, as long as proper debouncing and filtering
547 // is done in hardware :P
548 for (int i=0; i<=7; i++) {
549 // To be able to detect that a key has changed state, preserve the previous..
550 prev_keys[i] = keys[i];
552 // Select and read input.
554 keys[i] = digitalRead(A2);
560 void process_inputs(void )
562 int current_input, adc_in, fact;
565 for (current_input=0; current_input<MAX_INPUTS; current_input++) {
567 mplx_select(current_input);
568 adc_in = analogRead(0);
570 model.raw[current_input] = adc_in;
571 // New format on stick values
572 // The calculations happen around the center point, the values
573 // need to arrive at 0...100 of the range "center-to-edge",
574 // and must end up as negative on the ... negative side of center.
576 if ( adc_in < input_cal.center[current_input] )
578 // The stick is on the negative side, so the range is
579 // from the lowest possible value to center, and we must
580 // make this a negative percentage value.
581 max = input_cal.min[current_input];
582 min = input_cal.center[current_input];
587 // The stick is at center, or on the positive side.
588 // Thus, the range is from center to max, and
589 // we need positive percentages.
590 min = input_cal.center[current_input];
591 max = input_cal.max[current_input];
594 // Calculate the percentage that the current stick position is at
595 // in the given range, referenced to or from center, depending :P
596 model.stick[current_input] = fact * ((float)adc_in - min ) / (max - min);
598 // If this input is configured to be reversed, simply do a sign-flip :D
599 if ( model.rev[current_input] ) model.stick[current_input] *= -1;
601 // Dual-rate calculation :D
602 // This is very repetitive code. It should be fast, but it may waste code-space.
604 // Test to see if dualrate-switch #1 applies to channel...
605 if ( ( current_input == ( model.dr[0]-1) ) || ( current_input == ( model.dr[1]-1) ) )
607 if ( !keys[KEY_DR1] )
608 dr_val = ((float)model.dr[4])/100.0;
610 dr_val = ((float)model.dr[5])/100.0;
612 model.stick[current_input] *= dr_val;
615 // Test to see if dualrate-switch #1 applies to channel...
616 if ( ( current_input == ( model.dr[2]-1) ) || ( current_input == ( model.dr[3]-1) ) )
618 if ( !keys[KEY_DR1] )
619 dr_val = ((float)model.dr[6])/100.0;
621 dr_val = ((float)model.dr[7])/100.0;
623 model.stick[current_input] *= dr_val;
631 Timer1.stop(); // Make sure we do not run twice while working :P
635 set_ppm_output( LOW );
638 set_timer(seplength);
642 if ( cchannel >= model.channels )
644 set_ppm_output( HIGH );
645 long framesep = framelength - sum;
650 set_timer ( framesep );
656 set_ppm_output( HIGH );
658 // New format on stick values
659 // model.stick contains percentages, -100% to 100% in float. To make the timer-handling
660 // here as simple as possible. We want to calc the channel value as a "ratio-value",
661 // a float in the range 0..1.0. So, by moving the lower bound to 0, then cutting the
662 // range in half, and finally dividing by 100, we should get the ratio value.
663 // Some loss of presicion occurs, perhaps the algo' should be reconsidered :P
664 long next_timer = (( chwidht * ((model.stick[cchannel]+100)/200) ) + chmin);
665 // Do sanity-check of next_timer compared to chmax and chmin...
666 while ( chmax < next_timer ) next_timer--;
667 while ( next_timer < chmin ) next_timer++;
669 // Update the sum of elapsed time
672 // Done with channel separator and value,
673 // prepare for next channel...
676 set_timer ( next_timer );
684 for (current_input=0; current_input<MAX_INPUTS; current_input++) {
686 Serial.print("Input #");
687 Serial.print(current_input);
688 Serial.print(" pct: ");
689 Serial.print(model.stick[current_input]);
690 Serial.print(" raw value: ");
691 Serial.print(model.raw[current_input]);
692 Serial.print(" min: ");
693 Serial.print(input_cal.min[current_input]);
694 Serial.print(" max: ");
695 Serial.print(input_cal.max[current_input]);
698 Serial.print("Battery level is: ");
699 Serial.println(battery_val);
701 Serial.print("Average loop time:");
702 Serial.println(avg_loop_time);
707 void dr_inputselect( int no, int in )
709 if ( model.dr[menu_substate] < 0 ) model.dr[menu_substate] = 4;
710 if ( model.dr[menu_substate] > 4 ) model.dr[menu_substate] = 0;
712 lcd.setCursor(0 , 0);
713 lcd.print("D/R switch ");
716 lcd.setCursor(0 , 1);
721 if ( ! model.dr[menu_substate] ) lcd.print("Off");
722 else lcd.print(model.dr[menu_substate]);
724 if ( check_key(KEY_INC) ) {
725 model.dr[menu_substate]++;
728 else if ( check_key(KEY_DEC) ) {
729 model.dr[menu_substate]--;
742 if ( menu_substate == 4) state = keys[KEY_DR1];
743 else state = keys[KEY_DR2];
745 pos = 4 + (menu_substate - 4) * 2;
748 lcd.setCursor(0 , 0);
749 lcd.print("D/R switch ");
750 lcd.print( menu_substate - 3 );
752 lcd.setCursor(0 , 1);
753 lcd.print( state ? "HI" : "LO" );
754 lcd.print(" Value :");
756 lcd.print( model.dr[pos] );
758 if ( !keys[KEY_INC] ) {
759 if ( model.dr[pos] < 100) model.dr[pos] += 5;
762 else if ( !keys[KEY_DEC] ) {
763 if ( model.dr[pos] > -100) model.dr[pos] -= 5;
775 if ( displaystate != MENU )
778 if ( check_key(KEY_UP) && displaystate == VALUES ) {
779 displaystate = BATTERY;
782 else if ( check_key(KEY_UP) && displaystate == BATTERY ) {
783 displaystate = TIMER;
786 else if ( check_key(KEY_UP) && displaystate == TIMER ) {
787 displaystate = CURMODEL;
790 else if ( check_key(KEY_UP) && displaystate == CURMODEL ) {
791 displaystate = VALUES;
795 else if ( check_key(KEY_DOWN) ) {
801 digitalWrite(13, digitalRead(13) ^ 1 );
803 switch ( displaystate )
807 for (current_input=0; current_input<MAX_INPUTS; current_input++) {
808 // In channel value display, do a simple calc
809 // of the LCD row & column location. With 8 channels
810 // we can fit eight channels as percentage values on
811 // a simple 16x2 display...
812 if ( current_input < 4 )
814 col = current_input * 4;
819 col = (current_input-4) * 4;
822 // Overwriting the needed positions with
823 // blanks cause less display-flicker than
824 // actually clearing the display...
825 lcd.setCursor(col, row);
827 lcd.setCursor(col, row);
828 // Display uses percents, while PPM uses ratio....
829 // New format on stick values
830 lcd.print( (int)model.stick[current_input] );
837 lcd.print("Battery level: ");
838 lcd.setCursor(0 , 1);
839 lcd.print( (float)battery_val/10);
841 if ( battery_val < BATTERY_LOW ) lcd.print(" - WARNING");
842 else lcd.print(" - OK");
854 lcd.print("Timer: ");
855 lcd.print( clock_timer.running ? "Running" : "Stopped" );
856 lcd.setCursor(5 , 1);
857 if ( clock_timer.running )
859 clock_timer.value = millis() - (clock_timer.start + clock_timer.init);
861 hours = ( clock_timer.value / 1000 ) / 3600;
862 clock_timer.value = clock_timer.value % 3600000;
863 minutes = ( clock_timer.value / 1000 ) / 60;
864 seconds = ( clock_timer.value / 1000 ) % 60;
869 if ( minutes < 10 ) lcd.print("0");
870 lcd.print( minutes );
872 if ( seconds < 10 ) lcd.print("0");
873 lcd.print( seconds );
875 if ( check_key(KEY_INC) ) {
876 if ( !clock_timer.running && !clock_timer.start )
878 clock_timer.start = millis();
879 clock_timer.value = 0;
880 clock_timer.running = true;
881 } else if ( !clock_timer.running && clock_timer.start ) {
882 clock_timer.start = millis() - clock_timer.value;
883 clock_timer.running = true;
884 } else if ( clock_timer.running ) {
885 clock_timer.running = false;
888 } else if ( check_key(KEY_DEC) ) {
889 if ( !clock_timer.running && clock_timer.start ) {
890 clock_timer.value = 0;
891 clock_timer.start = 0;
892 clock_timer.init = 0;
902 lcd.print("Model #: ");
903 lcd.print( (int)current_model );
904 lcd.setCursor(0 , 1);
905 lcd.print("NAME (not impl)");
912 switch ( menu_mainstate )
915 lcd.print("In MENU mode!");
916 lcd.setCursor(0 , 1);
917 lcd.print("Esc UP. Scrl DN.");
919 if ( check_key(KEY_UP) ) {
920 displaystate = VALUES;
923 else if ( check_key(KEY_DOWN) ) {
924 menu_mainstate = INVERTS;
931 if ( menu_substate >= model.channels ) menu_substate = 0;
932 if ( menu_substate < 0) menu_substate = (model.channels - 1);
933 lcd.print("Channel invert");
934 lcd.setCursor(0 , 1);
936 lcd.print(menu_substate+1);
937 lcd.print( (model.rev[menu_substate] ? ": Invert" : ": Normal"));
939 if ( check_key(KEY_UP) ) {
940 menu_mainstate = TOP;
943 else if ( check_key(KEY_DOWN) ) {
944 menu_mainstate = DUALRATES;
948 if ( check_key(KEY_RIGHT) ) {
952 else if ( check_key(KEY_LEFT) ) {
956 else if ( check_key(KEY_INC) || check_key(KEY_DEC) ) {
957 model.rev[menu_substate] ^= 1;
963 if ( menu_substate > 5 ) menu_substate = 0;
964 if ( menu_substate < 0) menu_substate = 5;
966 if ( check_key(KEY_UP) ) {
967 menu_mainstate = INVERTS;
970 if ( check_key(KEY_DOWN) ) {
971 menu_mainstate = EXPOS;
974 if ( check_key(KEY_RIGHT) ) {
978 else if ( check_key(KEY_LEFT) ) {
982 switch (menu_substate)
985 dr_inputselect(0, 0);
988 dr_inputselect(0, 1);
991 dr_inputselect(1, 0);
994 dr_inputselect(1, 1);
1008 lcd.print("Input expo curve");
1009 lcd.setCursor(0 , 1);
1010 lcd.print("Not implemented");
1011 // Possible, if input values are mapped to +/- 100 rather than 0..1 ..
1012 // plot ( x*(1 - 1.0*cos (x/(20*PI)) )) 0 to 100
1013 // Run in wolfram to see result, adjust the 1.0 factor to inc/red effect.
1014 // Problem: -100 to 100 is terribly bad presicion, esp. considering that
1015 // the values started as 0...1024, and we have 1000usec to "spend" on channels.
1017 // NEW IDEA provided my ivarf @ hig: use bezier curves og hermite curves!
1018 // Looks like a promising idea, but the implementation is still a bitt off
1019 // on the time-horizon :P
1020 if ( check_key(KEY_UP ) ) {
1021 menu_mainstate = DUALRATES;
1024 if ( check_key(KEY_DOWN ) ) {
1025 menu_mainstate = DEBUG;
1031 lcd.setCursor(0 , 0);
1032 lcd.print("Dumping debug to");
1033 lcd.setCursor(0 , 1);
1034 lcd.print("serial port 0");
1036 if ( check_key(KEY_UP ) ) {
1037 // FIXME: Remember to update the "Scroll up" state!
1038 menu_mainstate = EXPOS;
1040 } else if ( check_key(KEY_DOWN ) ) {
1041 menu_mainstate = SAVE;
1047 lcd.print("Not implemented");
1048 lcd.setCursor(0 , 1);
1049 lcd.print("Press DOWN...");
1050 if ( check_key(KEY_DOWN ) ) menu_mainstate = TOP;