/** Configures the USB and radio communication then calls the processBytesFromUsb and * processBytesFromRadio functions. **/ void main() { // required by wixel api: // http://pololu.github.io/wixel-sdk/group__libraries.html systemInit(); usbInit(); radioLinkInit(); // wait for a wireless pairing // between two wixels // blink yellow LED while connection is being established while(!radioLinkConnected()) { yellowLedOn ^= 1; updateLeds(); delayMs(DELAY_MS); } // turn off LED yellowLedOn = 0; // process bytes while(1) { boardService(); updateLeds(); usbComService(); processBytesFromUsb(); processBytesFromRadio(); } }
void processSensors() { ambient = (int) map(analogRead(PIN_AMBIENT), 0, 1023, 0, 255); if (mute && ambient > threshold + hysteresis) { mute = false; updateLeds(); } else if (!mute && ambient < threshold - hysteresis) { mute = true; updateLeds(); } }
void FlashLightApp::beforeResume() { if (_buttonSubscription) { // Clear Button Queue of any up/down button pressed that have occured durind suspension _buttonSubscription->clear(); } updateLeds(); }
void putLeds() { String content = readContent(); StaticJsonBuffer<BUFFER_LENGTH + 1> jsonBuffer; JsonObject &json = jsonBuffer.parseObject(content); if (json.success()) { if (json.containsKey("green")) { green = json["green"]; } if (json.containsKey("green_duration") && json["green_duration"] > 0) { green_timeout = millis() + (int) json["green_duration"] * 1000; green_timeout = max(green_timeout, 1); } if (json.containsKey("red")) { red = json["red"]; } if (json.containsKey("red_duration") && json["red_duration"] > 0) { red_timeout = millis() + (int) json["red_duration"] * 1000; red_timeout = max(red_timeout, 1); } if (json.containsKey("yellow")) { yellow = json["yellow"]; } if (json.containsKey("yellow_duration") && json["yellow_duration"] > 0) { yellow_timeout = millis() + (int) json["yellow_duration"] * 1000; yellow_timeout = max(yellow_timeout, 1); } updateLeds(); sendResponse(204); } else { sendResponse(400); } }
void main() { uint32 f; /* frequency in hz */ f = 200; systemInit(); usbInit(); /* PWM duty cycle */ T1CC1L = 0x40; T1CC1H = 0x00; /* setup Timer 1, alt location 2 and prescaler 128*/ t1Init(IO_LOC_ALT_2, PRESCALER_128); /* setup Channel 1, compare mode, clear on compare up and peripheral*/ t1ChannelInit(CHANNEL1, COMPARE_MODE, CLR_ON_COMP_UP, PERIPHERAL); /* start Timer 1 by setting it's mode to modulo */ t1Mode(MODE_MODULO); /* set Timer 1 frequency */ setT1Frequency(f); while(1) { boardService(); updateLeds(); usbComService(); } }
/** * Stops motor */ void MotorShield::stop(uint8_t motorIndex) { digitalWrite(motor[motorIndex][0], LOW); digitalWrite(motor[motorIndex][1], LOW); analogWrite( motor[motorIndex][2], 0 ); updateLeds( motorIndex, STOP ); }
int main(void) { //-----------INITS------------// DDRB = (1 << PB2) | (1 << PB5) | (1 << PB3); //Setup SPI SPCR |= (1 << SPE) | (1 << MSTR); SPSR |= (1 << SPI2X); PORTB = 0x00; clearLeds(); //-------EVENT LOOP-----------// while(1) { for (int i=0; i<3; i++) { clearLeds(); for (int j=0; j<8; j++) { leds[j][i] = 0x0F; } updateLeds(); if (i == 0) _delay_ms(2000); else _delay_ms(1000); } for (int i=0; i<8; i++) { clearLeds(); leds[i][RED] = 0x0F; leds[i][GREEN] = 0x0F; leds[i][BLUE] = 0x0F; updateLeds(); _delay_ms(500); } } return(0); }
void checkLedTimeouts() { if (green_timeout != 0 && millis() > green_timeout) { green = false; green_timeout = 0; updateLeds(); } if (red_timeout != 0 && millis() > red_timeout) { red = false; red_timeout = 0; updateLeds(); } if (yellow_timeout != 0 && millis() > yellow_timeout) { yellow = false; yellow_timeout = 0; updateLeds(); } }
// now must be passed in, otherwise the cells will accumulate error and drop // out of sync with each other void Cell::update(uint32_t now) { this->now = now; updateChannel(this->hue); updateChannel(this->saturation); updateChannel(this->value); updateLeds(); }
void main() { systemInit(); usbInit(); while(1) { boardService(); updateLeds(); usbComService(); processBytesFromUsb(); } }
void main() { systemInit(); usbInit(); setup_DS1820(); while(1) { boardService(); updateLeds(); usbComService(); handleOneWire(); } }
void FlashLightApp::task() { ButtonSubscription buttonSubscription = Tilda::createButtonSubscription(UP | DOWN); _buttonSubscription = &buttonSubscription; updateLeds(); while(true) { Button button = _buttonSubscription->waitForPress(( TickType_t ) 1000); if (button == UP) { if (_lightLevel < 8) { _lightLevel++; } else { _lightLevel = 8; } updateLeds(); } else if (button == DOWN) { if (_lightLevel > 1) { _lightLevel--; } else { _lightLevel = 0; } updateLeds(); } } }
void main() { systemInit(); usbInit(); perTestTxInit(); while(1) { boardService(); updateLeds(); usbComService(); sendRadioBursts(); } }
void main() { systemInit(); usbInit(); analogInputsInit(); while(1) { boardService(); updateLeds(); usbComService(); sendReportIfNeeded(); } }
void main() { systemInit(); //Among other things, allocates byte arrays for sending commands. dynamixel_init(); // Oooh. what's this? setDigitalOutput(param_arduino_DTR_pin, LOW); ioTxSignals(0); //usbInit(); uart1Init(); uart1SetBaudRate(param_baud_rate); // Initial setting of serial mode updateSerialMode(); // Set up P1_5 to be the radio's TX debug signal. // P1DIR |= (1<<5); // IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode) // P1DIR |= 0x20; //Enable pin P1_5 while(1) { uint32 ms; uint16 now; uint16 speed; updateSerialMode(); boardService(); updateLeds(); errorService(); // Code for oscillating a servo back and forth ms = getMs(); // Get current time in ms now = ms % (uint32)10000; // 10 sec for a full swing if(now >= (uint16)5000){ // Goes from 0ms...5000ms now = (uint16)10000 - now; // then 5000ms...0ms } speed = interpolate(now, 0, 5000, 100, 900); // speed is really the position. ax12SetGOAL_POSITION(32, speed); delayMs(30); } }
/** * Sets output in specific direction and speed. * */ void MotorShield::move( uint8_t direction, uint8_t motorIndex, uint8_t speed) { if( direction == FORWARD ) { digitalWrite(motor[motorIndex][0], HIGH); digitalWrite(motor[motorIndex][1], LOW); analogWrite( motor[motorIndex][2], speed ); } else if( direction == BACKWARD ) { digitalWrite(motor[motorIndex][0], LOW); digitalWrite(motor[motorIndex][1], HIGH); analogWrite( motor[motorIndex][2], speed ); } updateLeds( motorIndex, direction ); }
void main() { systemInit(); usbInit(); usbComLineCodingChangeHandler = &lineCodingChanged; uart1Init(); lineCodingChanged(); while(1) { boardService(); updateLeds(); usbComService(); usbToUartService(); } }
void main(void) { systemInit(); radioQueueInit(); //Empfaenger initialisieren radioQueueAllowCrcErrors = 1; //Fehlerhafte Pakete zulassen uart1Init(); //Serielle Schnittstelle initialisieren lineCodingChanged(); //Einstellen der Schnittstellen Eigenschaft while(1) { updateLeds(); //Status der LEDs veraendern boardService(); usbComService(); radioToUart1Service(); //Empfangen der Daten } }
LinearColorSmoothing::LinearColorSmoothing( LedDevice * ledDevice, double ledUpdateFrequency_hz, int settlingTime_ms, unsigned updateDelay, bool continuousOutput) : QObject() , LedDevice() , _ledDevice(ledDevice) , _updateInterval(1000 / ledUpdateFrequency_hz) , _settlingTime(settlingTime_ms) , _timer() , _outputDelay(updateDelay) , _writeToLedsEnable(true) , _continuousOutput(continuousOutput) { _timer.setSingleShot(false); _timer.setInterval(_updateInterval); connect(&_timer, SIGNAL(timeout()), this, SLOT(updateLeds())); std::cout << "HYPERION (CS) INFO: Created linear-smoothing(interval_ms=" << _updateInterval << ";settlingTime_ms=" << settlingTime_ms << ";updateDelay=" << _outputDelay << std::endl; }
void main() { systemInit(); setDigitalOutput(param_arduino_DTR_pin, LOW); ioTxSignals(0); usbInit(); uart1Init(); uart1SetBaudRate(param_baud_rate); if (param_serial_mode != SERIAL_MODE_USB_UART) { radioComRxEnforceOrdering = 1; radioComInit(); } // Set up P1_5 to be the radio's TX debug signal. P1DIR |= (1<<5); IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode) while(1) { updateSerialMode(); boardService(); updateLeds(); errorService(); /* toggle_led();*/ if (param_serial_mode != SERIAL_MODE_USB_UART) { radioComTxService(); } usbComService(); switch(currentSerialMode) { case SERIAL_MODE_USB_RADIO: usbToRadioService(); break; case SERIAL_MODE_UART_RADIO: uartToRadioService(); break; case SERIAL_MODE_USB_UART: usbToUartService(); break; } } }
void setup() { EEPROM.setMemPool(0, EEPROM_SIZE); readEeprom(); pinMode(PIN_GREEN, OUTPUT); pinMode(PIN_RED, OUTPUT); pinMode(PIN_YELLOW, OUTPUT); green = false; red = false; yellow = false; mute = false; contentLength = 0; selfTest(); updateLeds(); Serial.begin(57600); wdt_enable(WDTO_4S); }
void main() { // uint32 ms; // uint32 now; // uint8 cmdrAlive = 0; // Here we define what pins we will be using for PWM. // uint8 CODE pwmPins[] = {ptrGunMotor->pwmpin}; uint8 CODE pwmPins[] = {11}; MOTOR gunMotor = MAKE_MOTOR_3_PIN(pwmPins[0], 12, 13); //(PWM, B, A) MOTOR *ptrGunMotor = &gunMotor; // setDigitalOutput(param_arduino_DTR_pin, LOW); // ioTxSignals(0); // Initialize UARTs uart0Init(); uart0SetBaudRate(param_baud_rate_UART); uart1Init(); uart1SetBaudRate(param_baud_rate_XBEE); pwmStart((uint8 XDATA *)pwmPins, sizeof(pwmPins), 10000); guns_firing_duration = 125; // time in ms gunbutton = zFALSE; solenoid_on_duration = 80; // time in ms solenoidbutton = zFALSE; laserbutton = zFALSE; systemInit(); // Initialize other stuff index_cmdr = -1; /// MAIN LOOP /// while(1) { // updateSerialMode(); boardService(); updateLeds(); errorService(); // cmdr counts down from CMDR_ALIVE_CNT by -1 whenever no packets are received? cmdrAlive = (uint8) CLAMP(cmdrAlive + CmdrReadMsgs(), 0, CMDR_ALIVE_CNT); // ms = getMs(); // Get current time in ms // now = getMs(); // now = ms % (uint32)10000; // 10 sec for a full swing // if(now >= (uint16)5000){ // Goes from 0ms...5000ms // now = (uint16)10000 - now; // then 5000ms...0ms // } // speed = interpolate(now, 0, 5000, 100, 900); if (laserbutton == zTRUE && cmdrAlive > 0){ // uart0TxSendByte('L'); setDigitalOutput(param_laser_pin, HIGH); } else {setDigitalOutput(param_laser_pin, LOW);} //FIRE THE GUNS!!!!! //Resets timer while gunbutton is held down. if (gunbutton == zTRUE){ // uart0TxSendByte('Z'); guns_firing = zTRUE; setMotorSpeed(ptrGunMotor, -60); //NOTE: (7.2 / 12.6) * 127 = 72.5714286 guns_firing_start_time = getMs(); } //Check whether to stop firing guns if (guns_firing && clockHasElapsed(guns_firing_start_time, guns_firing_duration)){ // uart0TxSendByte('X'); guns_firing = zFALSE; setMotorSpeed(ptrGunMotor, 0); //NOTE: (7.2 / 12.6) * 127 = 72.5714286 guns_firing_start_time = getMs(); } //Activate solenoid for hopup feed unjammer if (solenoidbutton == zTRUE){ // uart0TxSendByte('Z'); solenoid_on = zTRUE; setDigitalOutput(10, HIGH); solenoid_on_start_time = getMs(); } //Check whether to disable solenoid if (solenoid_on && clockHasElapsed(solenoid_on_start_time, solenoid_on_duration)){ // uart0TxSendByte('X'); solenoid_on = zFALSE; setDigitalOutput(10, LOW); solenoid_on_start_time = getMs(); } delayMs(5); } }
void main() { int8 SPI_SEND = 0; int8 prev_send = 0; systemInit(); setDigitalOutput(param_arduino_DTR_pin, LOW); ioTxSignals(0); usbInit(); spi0MasterInit(); spi0MasterSetFrequency(38400); // uart1Init(); // uart1SetBaudRate(param_baud_rate); if (param_serial_mode != SERIAL_MODE_USB_SPI) { radioComRxEnforceOrdering = 1; radioComInit(); } // Set up P1_5 to be the radio's TX debug signal. //P1DIR |= (1<<5); //IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode) while(1) { updateSerialMode(); boardService(); updateLeds(); //errorService(); if(!spi0MasterBusy() && SPI_SEND != prev_send){ spi0MasterSendByte(SPI_SEND); prev_send = SPI_SEND; } if (param_serial_mode != SERIAL_MODE_USB_SPI) { radioComTxService(); } usbComService(); // switch(currentSerialMode) // { // case SERIAL_MODE_USB_RADIO: usbToRadioService(); break; // case SERIAL_MODE_SPI_RADIO: uartToRadioService(); break; // case SERIAL_MODE_USB_SPI: usbToUartService(); break; // } switch(usbComRxReceiveByte()){ case 0: // STOP SPI_SEND += 15; SPI_SEND = (SPI_SEND%255); break; case 1: // Initialize SPI_SEND -= 15; SPI_SEND = (SPI_SEND%255); break; } } }