// the loop routine runs over and over again forever: void loop() { // TODO add print status sampleSensors(); speedSteeringControlMap(); adjustForLeanMode(); steerControl(); leanControl(); brakeControl(); hydraulicControl(); tractionMotorCommandProcessing(); setThrottle(); setRevValues(); //analog inputs joystickValy = readAnalog(joystickFBSensor); joystickValx = readAnalog(joystickLRSensor); int PumpVal = readAnalog(A2); int BrakeSensor = readAnalog(A3); //PWM inputs int SteerSensor = readAnalog(A4); int LeanSensor = readAnalog(A4); int SpeedSensor = readAnalog(A4); PWMOutput2(joystickValx, SteerSensor, 10); button_test(); led_test(); digitalWrite(pSpeedSenseIn, HIGH); delay(30); // delay in between reads for stability }
/* * * main( ) * */ void main( void ) { /* Initialize BSL */ EZDSP5535_init( ); /* Display test ID */ printf( "\nTesting LEDs...\n"); /* Call test function */ TestFail = led_test( ); /* Check for test fail */ if ( TestFail != 0 ) { /* Print error message */ printf( " FAIL... error code %d... quitting\n", TestFail ); } else { /* Print pass message */ printf( " PASS\n" ); printf( "\n***ALL Tests Passed***\n" ); } StopTest(); }
void setup(void) { // Enable the LED pins as outputs LED_DDR = LED_1 | LED_2 | LED_3 | LED_4 | LED_5 | LED_6 | LED_7; #if defined(BUTTON_DDR) BUTTON_DDR &= ~(1 << BUTTON_BIT); #endif // Enable the pullup resistor on the input pin tied to the push button BUTTON_PORT = (1 << BUTTON_BIT); // Enable TIMER1 with no clock scaling TCCR1A = 0; TCCR1B = (1 << WGM12) | (1 << CS10); #if defined(__AVR_ATtiny2313__) TIMSK = (1 << OCIE1A); #else TIMSK1 = (1 << OCIE1A); #endif // Set TIMER1's output compare register A to 0xff and counter to 0 TCNT1 = 0; OCR1A = 256; // Enable the watchdog timer, no-prescaling (16ms interrupt) WDTCSR = (1 << WDCE) | (1 << WDE); WDTCSR = (1 << WDE) | (1 << WDIE); // When the external interrupt INT0 is enabled, we will // trigger when the pin goes to a logical low INTERRUPT_CONT &= ~((1 << ISC00) | (1 <<ISC01)); // Just to be sure button_state = 1; finish_roll = 0; // And more initializations sequence_index = 0; pattern_hold = pgm_read_byte(&(sequences[0][HOLD_OFFSET])); pattern_fade = pgm_read_byte(&(sequences[0][FADE_OFFSET])); pattern_index = PATTERN_OFFSET; #if defined(ARDUINO) // Enable global interrupts sei(); led_test(); #endif }
int main() { uart_init(); myputc('1'); myputc('2'); myputc('3'); myputc('4'); myputc('5'); myputc('6'); myputs("hello world!\n"); led_test(); return 0; }
int main(void) { // Disable interrupts asm("cli"); // Initializations setup(); // Enable interrupts asm("sei"); // LED test led_test(); // And get to work while(1) loop(); return(0); }
int main(void) { unsigned char c; init_devices(); PORTD = 0x00; uart_puts("/*****************************/\r\n"); led_test(); c='a'; while(1) { c = uart_getc(); uart_putc(c); } while(1) PORTD = 0xff; return 0; }
int main() { led_test(); return 0; }
void action_function(keyrecord_t *event, uint8_t id, uint8_t opt) { #ifdef AUDIO_ENABLE int8_t sign = 1; #endif if(id == LFK_ESC_TILDE){ // Send ~ on shift-esc void (*method)(uint8_t) = (event->event.pressed) ? &add_key : &del_key; uint8_t shifted = get_mods() & (MOD_BIT(KC_LSHIFT) | MOD_BIT(KC_RSHIFT)); if(layer_state == 0){ method(shifted ? KC_GRAVE : KC_ESCAPE); }else{ method(shifted ? KC_ESCAPE : KC_GRAVE); } send_keyboard_report(); }else if(event->event.pressed){ switch(id){ case LFK_SET_DEFAULT_LAYER: // set/save the current base layer to eeprom, falls through to LFK_CLEAR eeconfig_update_default_layer(1UL << opt); default_layer_set(1UL << opt); case LFK_CLEAR: // Go back to default layer layer_clear(); break; #ifdef ISSI_ENABLE case LFK_LED_TEST: led_test(); break; #endif #ifdef AUDIO_ENABLE case LFK_CLICK_FREQ_LOWER: sign = -1; // continue to next statement case LFK_CLICK_FREQ_HIGHER: click_hz += sign * 100; click(click_hz, click_time); break; case LFK_CLICK_TOGGLE: if(click_toggle){ click_toggle = 0; click(4000, 100); click(1000, 100); }else{ click_toggle = 1; click(1000, 100); click(4000, 100); } break; case LFK_CLICK_TIME_SHORTER: sign = -1; // continue to next statement case LFK_CLICK_TIME_LONGER: click_time += sign; click(click_hz, click_time); break; #endif case LFK_DEBUG_SETTINGS: dprintf("Click:\n"); dprintf(" toggle: %d\n", click_toggle); dprintf(" freq(hz): %d\n", click_hz); dprintf(" duration(ms): %d\n", click_time); break; } } }
int main (void) { cc3_histogram_pkt_t my_hist; cc3_color_info_pkt_t s_pkt; cc3_frame_diff_pkt_t fd_pkt; cc3_timer_wait_ms (500); cc3_gpio_set_mode (0, CC3_GPIO_MODE_SERVO); cc3_gpio_set_mode (1, CC3_GPIO_MODE_SERVO); cc3_gpio_set_mode (2, CC3_GPIO_MODE_SERVO); cc3_gpio_set_mode (3, CC3_GPIO_MODE_SERVO); // configure uarts cc3_uart_init (0, CC3_UART_RATE_115200, CC3_UART_MODE_8N1, CC3_UART_BINMODE_TEXT); cc3_uart_init (1, CC3_UART_RATE_38400,//CC3_UART_RATE_115200, CC3_UART_MODE_8N1, CC3_UART_BINMODE_BINARY); // Make it so that stdout and stdin are not buffered setvbuf (stdout, NULL, _IONBF, 0); setvbuf (stdin, NULL, _IONBF, 0); printf( "Opening UART1 file pointer\n" ); FILE *fp = cc3_uart_fopen(1, "r"); if (fp) { printf("Success"); int i = 0; while (1) { fprintf(fp, "i = %08d\n", i++); } } printf( "Calling camera init\n" ); cc3_camera_init (); cc3_camera_set_colorspace (CAM_COLOURS); cc3_camera_set_resolution (CAM_FORMAT); cc3_pixbuf_frame_set_coi (CC3_CHANNEL_ALL);//for full 'colour_info' //cc3_camera_set_colorspace (CC3_COLORSPACE_YCRCB);?All switches handled? //cc3_camera_set_resolution (CC3_CAMERA_RESOLUTION_HIGH);// 352, 288 //cc3_pixbuf_frame_set_subsample(CC3_SUBSAMPLE_RANDOM, 2, 2); printf( "Camera init done\n%d x %d\n", cc3_g_pixbuf_frame.raw_width, cc3_g_pixbuf_frame.raw_height ); // frame difference fd_pkt.coi = CC3_CHANNEL_ALL; fd_pkt.template_width = 16;//8; fd_pkt.template_height = 16;//8; fd_pkt.total_x = cc3_g_pixbuf_frame.width; fd_pkt.total_y = cc3_g_pixbuf_frame.height; fd_pkt.load_frame = 1; // load a new frame fd_pkt.previous_template = malloc (fd_pkt.template_width * fd_pkt.template_height * sizeof (uint32_t)); if (fd_pkt.previous_template == NULL) printf ("Malloc FD startup error!\r"); cc3_camera_set_auto_white_balance (true); cc3_camera_set_auto_exposure (true); // The LED test masks the stabilization delays (~2000ms) printf ("Waiting for image to stabilize\n"); led_test (); cc3_camera_set_auto_white_balance (false); cc3_camera_set_auto_exposure (false); // printf ("\nPush button on camera back to continue\n"); // while (!cc3_button_get_state ()) // ; cc3_led_set_state (0, true); cc3_pixbuf_load (); my_hist.channel = CC3_CHANNEL_ALL; my_hist.bins = 24; my_hist.hist = malloc (my_hist.bins * sizeof (uint32_t)); while (true) { printf ("<3 EE\n 0x%02X\n ", (unsigned int)cc3_timer_get_current_ms()); // Grab an image and take a frame difference of it cc3_pixbuf_load (); frame_diff (&fd_pkt); // Rewind and take a histogram of it cc3_pixbuf_rewind (); //get_histogram (&my_hist); // Rewind and get some stats cc3_pixbuf_rewind (); get_mean(&s_pkt); printf( "min = [%d,%d,%d] mean = [%d,%d,%d] max = [%d,%d,%d] deviation = [%d,%d,%d] ", s_pkt.min.channel[0],s_pkt.min.channel[1],s_pkt.min.channel[2], s_pkt.mean.channel[0],s_pkt.mean.channel[1],s_pkt.mean.channel[2], s_pkt.max.channel[0],s_pkt.max.channel[1],s_pkt.max.channel[2], s_pkt.deviation.channel[0],s_pkt.deviation.channel[1],s_pkt.deviation.channel[2] ); /* printf ("hist[%d] = ", my_hist.bins); for (uint32_t i = 0; i < my_hist.bins; i++) { printf ("%08X ", my_hist.hist[i]); // sample non-blocking serial routine if (!cc3_uart_has_data (1)) { cc3_gpio_set_servo_position (0, SERVO_MID); cc3_gpio_set_servo_position (1, SERVO_MID); } } */ printf ("\n"); cc3_timer_wait_ms(400); // if (cc3_button_get_state()) // break; } printf("\n\nAll done!\n"); return 0; }
void main() { u8 cur_detect_pos=1; OSCCR = 0x20; // internal OSC 8MHz BITCR = 0x2E; // BIT 16.384ms delay_ms(16); LVRCR = 0x02; // builtin reset 2.0V set, LVRCR.0=0 enable !!! InitConfig(); WDTDR = 0xFF; ClrWdt(); //timer0 as system tick T0DR = 38; T0CR = 0x8D; //ADC ADCCRH = 0x07; ADCCRL = 0x90; //interrupt IE = 0x20; IE1 = 0x00; IE2 = 0x02; //enable timer0 overflow IE3 = 0x00; EIPOL0L = 0x00; EIFLAG0 = 0; EIFLAG1 = 0; IIFLAG = 0; IE |= (1<<7); //global interrupt // LED1_G_ON();delay_ms(500); // LED1_G_OFF(); #ifdef IO_DEBUG led_test(); #endif if(GET_BATTERY_STATUS()) // AA battery status { gTestMode = TEST_AA_BATTERY; } else { gTestMode = TEST_AAA_BATTERY; } testLoop(); while(1) { ClrWdt(); NOP(); } }
void goto_sleep(void) { // Disable the watchdog timer's interrupt vector, WDIE // On the Arduino (ATmega328p at least), it suffices to // just set WDTCSR = 0. So what follows may be overkill // on some AVRs asm("cli"); asm("wdr"); // Make sure that the watchdog interrupt is not renewed by the // watchdog interrupt sleeping = 1; MCUSR = 0; WDTCSR |= (1 << WDCE) | (1 << WDE); WDTCSR = 0; // Again, enable the pull up resistor on the input port BUTTON_PORT = (1 << BUTTON_BIT); // Shut down the LEDs leds_on = 0; old_leds_on = 0; LED_PORT &= ~(LED_1 | LED_2 | LED_3 | LED_4 | LED_5 | LED_6 | LED_7); // Set the sleep mode set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Use INT0 and run the INT0 interrupt routine when pin 2 goes LOW // When the external interrupt INT0 is enabled, we will // trigger when the pin goes to a logical low INTERRUPT_CONT &= ~((1 << ISC00) | (1 <<ISC01)); INTERRUPT_MASK = (1 << INT0); // Enable the sleep bit in MCUCR register sleep_enable(); // And now go to sleep asm("sei"); sleep_mode(); // We will resume here when awoken... // Disable sleep... sleep_disable(); // Disable INT0 thus preventing the INT0 interrupt from being // executed during normal operation INTERRUPT_MASK &= ~(1 << INT0); // Allow the watchdog interrupt to renew itself sleeping = 0; // Re-enable the watchdog timer's interrupt vector // The following is overkill on some AVRs. For instance, on the // ATmege328p, just doing "WDTCSR = 1 << WDIE" is sufficient. WDTCSR = (1 << WDCE) | (1 << WDE); WDTCSR = (1 << WDE) | (1 << WDIE); // Run throught the LED test led_test(); }