void init(void) { // Set up the RTI. RTICTL = 0x17;// Generate an. intr. every 2ms. // Set up the KISR. DDRP |= 0x0F; // bitset PP0-3 as outputs (rows) DDRH &= 0x0F; // bitclear PH4..7 as inputs (columns) PIFH = 0xFF; // Clear previous interrupt flags PPSH = 0xF0; // Rising Edge PERH = 0x00; // Disable pulldowns PIEH |= 0xF0; // Local enable on columns inputs SETMSK(PTM, 0x08); /* Pass through the latch to the keypad. */ PTP = 0x0F; // Set scan row(s) CLRMSK(PTM, 0x08); // Set up the clock (TC0) ISR. TSCR1 = 0x90; // Enable TCNT and fast-flags clear. TSCR2 = 0x05; // Set a pre-scale factor of 32x, no overflow interrupts. TIOS = 0x01; // Enable OC0. SETMSK(TIE, 0x01); // Enable interrupts on OC0. TC0 = TCNT + TC0_TICK_LENGTH; // Set up the timeout on the output compare. // Setup the motor // Output for all channels is high at beginning // of Period and low when the duty count is reached PWMPOL = 0xFF; SETMSK(PWMCLK,0x10); // Select Clock SB for channel 7 PWMPRCLK = 0x70; // Prescale ClockB by busclock/128 PWMSCLA = 0; // Total Divide: EClock/512 PWMCAE = 0xFF; // Make sure Chan7 is in left aligned output mode PWMCTL = 0x00; // Combine PWMs 6 and 7. PWME = 0x80; // Enable PWM Channel 7 //For Motor Direction Control SETMSK(DDRP,0x60); //Setup Pulse Accumulator A for Optical Sensor Input SETMSK(PAFLG, 0x03); // Clear out the interrupt flag PACTL = 0x50; // Enable PACA PWMPER7 = 100; PWMDTY7 = 0; INTR_ON(); // Set up the LCD. clearLEDs(); LCD2PP_Init(); SETMSK(DDRT, 0x70); // This keeps the accumulator from messing up CLRMSK(DDRT, 0x80); // Actually lets us read from the optical sensor SETMSK(PTT, 0x70); // This keeps the accumulator from messing up }
TM1638::TM1638() : _dotMask(0) { port_setup(); send_cmd(TM_DATA_CMD | TM_WRITE_DISP); send_cmd(TM_DISP_CTRL | TM_DISP_ENABLE | TM_DISP_PWM_MASK); clear(); clearLEDs(); }
void play_buzz_anim(int team) { if(team < 0 || team >= NUM_TEAMS) return; clearLEDs(); int right_dist = (NUM_LEDS - teams[team].end) - 1; //'Swoop' part of the animation where leds stream from the left and right //to focus on the target range for(int frame = 0; frame < NUM_FRAMES; frame++) { float pos = (float) frame / (float) NUM_FRAMES; int leftpos = round((float) teams[team].st * pos); int rightpos = (NUM_LEDS - round((float) right_dist * pos)) - 1; if(SWOOP_TEAM_COLS) { //Use team colours for the swoop leds[leftpos] = teamcol[team]; leds[rightpos] = teamcol[team]; } else { //Use random colours leds[leftpos] = CHSV(random(255), 255, 255); leds[rightpos] = CHSV(random(255), 255, 255); } fadeAllLeds(SWOOP_FADE_SPEED); FastLED.show(); delay(FRAME_DELAY); } //Swoop complete, focus on the target range for(int i = teams[team].st; i <= teams[team].end; i++) { leds[i] = teamcol[team]; } FastLED.show(); while(1) { int rv1 = fadeLeds(2, 0, teams[team].st - 1); int rv2 = fadeLeds(2, teams[team].end + 1, NUM_LEDS - 1); if(rv1 == 0 && rv2 == 0) break; FastLED.show(); delay(POST_SWOOP_FADE_SPEED); } }
//! Update internal state with new parameter values. void onUpdateParameters(void) { clearLEDs(); for (unsigned i = 0; i < m_args.led_names.size(); ++i) { LED* led = new LED; led->id = i; led->name = m_args.led_names[i]; led->brightness.name = led->name; led->brightness.value = 0; m_led_by_name[led->name] = led; m_led_by_id[led->id] = led; } setConfig(); m_wdog.setTop(m_args.wdog_tout); }
/* * Initialize GPIO */ int initGpio() { //Variables int status; //Initialize GPIOs status = XGpio_Initialize(&outGpio, OUTGPIO_DEVICE_ID); status = XGpio_Initialize(&inGpio, INGPIO_DEVICE_ID); //Set Direction XGpio_SetDataDirection(&outGpio, LED_CHANNEL, DIR_OUT); XGpio_SetDataDirection(&inGpio, 1, DIR_IN); XGpio_SetDataDirection(&inGpio, 2, DIR_IN); //Clear LEDs if (status == XST_SUCCESS) { clearLEDs(status, &outGpio); } return XST_SUCCESS; }
/** INITIALIZATION ****************************************************/ void init(void) { // Set up the RTI. RTICTL = 0x17;// Generate an. intr. every 2ms. // Set up the buzzer. SETMSK(DDRK, BUZZER_MASK); // Set up the KISR. DDRP |= 0x0F; // bitset PP0-3 as outputs (rows) DDRH &= 0x0F; // bitclear PH4..7 as inputs (columns) PIFH = 0xFF; // Clear previous interrupt flags PPSH = 0xF0; // Rising Edge PERH = 0x00; // Disable pulldowns PIEH |= 0xF0; // Local enable on columns inputs SETMSK(PTM, 0x08); /* Pass through the latch to the keypad. */ PTP = 0x0F; // Set scan row(s) CLRMSK(PTM, 0x08); // Set up the clock (TC0) ISR. TSCR1 = 0x90; // Enable TCNT and fast-flags clear. TSCR2 = 0x05; // Set a pre-scale factor of 32x, no overflow interrupts. TIOS = 0x01; // Enable OC0. SETMSK(TIE, 0x01); // Enable interrupts on OC0. TC0 = TCNT + TC0_TICK_LENGTH; // Set up the timeout on the output compare. //This sets up the temperature sensor thing ATD0CTL2 = 0xFA; // Enables ATD ATD0CTL3 = 0x00; // Continue conversions ATD0CTL4 = 0x60; // Select 10-bit operation // Set sample time to 16 ATD clock period // Set clock prescale to 0 ATD0CTL5 = 0x86; // Right justified, Unsigned and single scan INTR_ON(); // Set up the LCD. clearLEDs(); LCD2PP_Init(); }
int main(void) { SystemInit(); clearLEDs(); uint8_t currentLED = 0; uint8_t buttonState = 0; uint8_t mode = 0; int8_t direction = 0; for(;;) { /* uses an idle function to absorb extra time--at OCR0A = 15, should run at 120 Hz (every 8.3 ms) */ while(tick == 0) { } //idle tick = 0; buttonState = test_for_press_only(); if (buttonState & 0x01) { valueLEDs[currentLED] = 0; if (currentLED == 0) { currentLED = 15; } else { currentLED--; } valueLEDs[currentLED] = 10; } if (buttonState & 0x02) { valueLEDs[currentLED] = 0; if (currentLED == 15) { currentLED = 0; } else { currentLED++; } valueLEDs[currentLED] = 10; } displayFader(); updateLEDs(currentLEDstate1, currentLEDstate2); } }
~Task(void) { clearLEDs(); }