bool input(std::string text = "") { bool retval = false; printf(text.c_str()); while (!isButtonPressed('a', false)) if (isButtonPressed('t', false)) retval = true; printf("\n"); return retval; }
void checkLEDsSettingButtons() { if (isButtonPressed(SB4)) { LEDon(LED_GREEN); } if (isButtonPressed(SB3)) { LEDon(LED_RED); } }
/* * Loads, sorts and displays the closest restaurants to location on map * passed in, filtered by rating. */ void displayClosestRestaurants(uint16_t horiz, uint16_t vert, uint8_t minimumRating) { RestDist distances[RESTAURANTS_COUNT]; uint16_t restaurantCount = loadDistances(horiz, vert, minimumRating, distances); Serial.print("# of Restauraunts loaded: "); Serial.println(restaurantCount); sortDistances(distances, restaurantCount); int16_t startingIndex = 0; int8_t scrollScale = 10; writeOutRestaurants(startingIndex, distances, restaurantCount); // wait for button to be pressed while(!isButtonPressed()) { // following code implements scrolling up or down // the list of restaurants loaded previously uint16_t currentVertical = getVertical(); int16_t shiftValue = 0; if(currentVertical > verticalMidpoint) { shiftValue = scrollScale; } else if (currentVertical < verticalMidpoint) { shiftValue = -scrollScale; } if(shiftValue) { uint16_t endIndex = startingIndex + 20; // If we're scrolling up or we're not already at the end of the list, // go ahead and scroll if(shiftValue < 0 || endIndex < restaurantCount) { startingIndex = startingIndex + shiftValue; if(startingIndex < 0) { // Don't want to scroll past the top! startingIndex = 0; } else { // Don't want to scroll past the end! if (startingIndex >= restaurantCount) { startingIndex = restaurantCount - 1; } writeOutRestaurants((uint16_t) startingIndex, distances, restaurantCount); } } } delay(100); } // wait for button to be released while(isButtonPressed()) { } }
void loop() { uint8_t ratingFilter = getRatingFilter(); uint16_t horiz = getHorizontal(); uint16_t vert = getVertical(); lightUpRatingLEDs(ratingFilter); tft.drawPixel(horiz, vert, 0); if(isButtonPressed()) { // wait for button to be released while(isButtonPressed()) { } displayClosestRestaurants(horiz, vert, ratingFilter * 2); drawMap(); } lcd_image_draw(&map_image, &tft, horiz, vert, horiz, vert, 1, 1); }
void processAudio(AudioBuffer &buffer){ float freq = getParameterValue(PARAMETER_A)*6; float decay = getParameterValue(PARAMETER_C); freq = 110.f * powf(2, freq); osc->setFrequency(freq); osc->setDecay(decay); if(buttonstate != isButtonPressed(PUSHBUTTON)){ buttonstate = isButtonPressed(PUSHBUTTON); if(buttonstate) // rising edge osc->trigger(); } FloatArray left = buffer.getSamples(LEFT_CHANNEL); osc->getSamples(left); }
void loop() { delay(250); toggleLED(); if (isButtonPressed()) { if (servo1.attached()) detach(); else attach(); } if (!servo1.attached()) return; int32 average = averageAnalogReads(250); int16 angle1 = (int16)map(average, 0, 4095, MIN_ANGLE1, MAX_ANGLE1); int16 angle2 = (int16)map(average, 0, 4095, MIN_ANGLE2, MAX_ANGLE2); print_buf("pot reading = %d, angle 1 = %d, angle 2 = %d.", average, angle1, angle2); servo1.write(angle1); servo2.write(angle2); int16 read1 = servo1.read(); int16 read2 = servo2.read(); print_buf("write/read angle 1: %d/%d, angle 2: %d/%d", angle1, read1, angle2, read2); ASSERT(abs(angle1 - read1) <= 1); ASSERT(abs(angle2 - read2) <= 1); print_buf("pulse width 1: %d, pulse width 2: %d", servo1.readMicroseconds(), servo2.readMicroseconds()); Serial2.println("\n--------------------------\n"); }
void board_start(const char* program_name) { // Set up the LED to steady on pinMode(BOARD_LED_PIN, OUTPUT); digitalWrite(BOARD_LED_PIN, HIGH); // Setup the button as input pinMode(BOARD_BUTTON_PIN, INPUT); digitalWrite(BOARD_BUTTON_PIN, HIGH); SerialUSB.begin(); SerialUSB.println("Press BUT"); // Wait for button press while ( !isButtonPressed() ) { } SerialUSB.println("Welcome!"); SerialUSB.println(program_name); int i = 11; while (i--) { toggleLED(); delay(50); } }
void processAudio(AudioBuffer &buffer){ if(isButtonPressed(PUSHBUTTON)) reset(); dt = getParameterValue(PARAMETER_A)*getParameterValue(PARAMETER_A)*0.0250; float rotateX = getParameterValue(PARAMETER_B)*M_PI; float rotateY = getParameterValue(PARAMETER_C)*M_PI; float rotateZ = getParameterValue(PARAMETER_E)*M_PI; float gainL, gainR; gainL = gainR = getParameterValue(PARAMETER_D)*2/25.0; int size = buffer.getSize(); float* left = buffer.getSamples(0); float* right = buffer.getSamples(1); float dx, dy, dz; updateMatrix(rotateX, rotateY, rotateZ); for(int i=0;i<size;i++){ dx = a*(y - x); dy = (x * (c - z) - y); dz = (x*y - b * z); x += dx*dt; y += dy*dt; z += dz*dt; P[0] = x; P[1] = y; P[2] = z-25; // centre on z axis rotateP(); left[i] = Pprime[0] * gainL; right[i] = Pprime[1] * gainR; } // debugMessage("x/y/z", x, y, z); }
void buttonAndLED(TaskState *self){ startCoroutine(); while(1){ turnOffLED(); while(isButtonPressed()==FALSE){ yield(); } turnOnLED(); while(isButtonPressed()==TRUE){ yield(); } while(isButtonPressed()==FALSE){ yield(); } endCoroutine(); } }
bool isButtonPressed(int buttonCode, int modifiers, bool strict) { if(checkModifiers(modifiers, strict)) { return isButtonPressed(buttonCode); } return false; }
void TraktorF1MK2::processButtons(const Transfer& input_) { bool shiftPressed(isButtonPressed(input_, Button::Shift)); Device::Button changedButton(Device::Button::Unknown); bool buttonPressed(false); for (int i = 0; i < kF1MK2_buttonsDataSize - 1; i++) // Skip the last byte (encoder value) { for (int k = 0; k < 8; k++) { uint8_t btn = (i * 8) + k; Button currentButton(static_cast<Button>(btn)); if (currentButton == Button::Shift) { continue; } buttonPressed = isButtonPressed(input_, currentButton); if (buttonPressed != m_buttonStates[btn]) { m_buttonStates[btn] = buttonPressed; changedButton = deviceButton(currentButton); if (changedButton != Device::Button::Unknown) { if (currentButton >= Button::Pad8 && currentButton <= Button::Pad9) { keyChanged(btn, buttonPressed ? 1.0 : 0.0, shiftPressed); } else { buttonChanged(changedButton, buttonPressed, shiftPressed); } } } } } // encoder uint8_t currentValue = input_.data()[kF1MK2_buttonsDataSize]; if (currentValue != m_encoderValue) { bool valueIncreased = ((static_cast<uint8_t>(m_encoderValue) < currentValue) || ((m_encoderValue == 0xff) && (currentValue == 0x00))) && (!((m_encoderValue == 0x0) && (currentValue == 0xff))); m_encoderValue = currentValue; encoderChanged(0, valueIncreased, shiftPressed); } // pots/faders for (uint8_t potIndex = 0, i = kF1MK2_buttonsDataSize + 1; potIndex < 8; i += 2, potIndex++) { unsigned value = (input_.data()[i]) | (input_.data()[i + 1] << 8); if (m_potentiometersValues[potIndex] != value) { m_potentiometersValues[potIndex] = value; controlChanged(potIndex, value / 1024.0, shiftPressed); } } }
void processAudio(AudioBuffer &buffer) { float tune = getParameterValue(PARAMETER_A)*10.0 - 6.0; float fc = getParameterValue(PARAMETER_B)*10.0 - 4.0; float q = getParameterValue(PARAMETER_C)*3+0.75; float shape = getParameterValue(PARAMETER_E)*2; float pw = 0.5; if(shape > 1.0){ pw += 0.49*(shape-1.0); // pw 0.5 to 0.99 shape = 1.0; // square wave } float df = getParameterValue(PARAMETER_D)*4; int di = (int)df; float gain = 0.0f; switch(di){ // a/d case 0: // l/s env.setAttack(1.0-df); env.setRelease(0.0); break; case 1: // s/s env.setAttack(0.0); env.setRelease(df-1); break; case 2: // s/l env.setAttack(df-2); env.setRelease(1.0); break; case 3: // l/l env.setAttack(1.0); env.setRelease(1.0); gain = df-3; break; } env.trigger(isButtonPressed(PUSHBUTTON), getSamplesSinceButtonPressed(PUSHBUTTON)); FloatArray left = buffer.getSamples(LEFT_CHANNEL); FloatArray right = buffer.getSamples(RIGHT_CHANNEL); // vco hz.setTune(tune); float lfreq = hz.getFrequency(left[0]); osc.setFrequency(lfreq); osc.setShape(shape); osc.setPulseWidth(pw); osc.getSamples(left); // vcf hz.setTune(fc); fc = hz.getFrequency(right[0]); fc = min(0.999, max(0.01, fc/(getSampleRate()*2))); // normalised and bounded filter->setLowPass(fc, q); right.copyFrom(left); filter->process(right); right.multiply(0.8-q*0.2); // gain compensation for high q // vca env.getEnvelope(envelope); envelope.add(gain); left.multiply(envelope); right.multiply(envelope); }
uint8 waitForButtonPress(uint32 timeout) { uint32 start = millis(); uint32 time; if (timeout == 0) { while (!isButtonPressed()) ; return true; } do { time = millis(); /* properly handle wrap-around */ if ((start > time && time + (0xffffffffU - start) > timeout) || time - start > timeout) { return false; } } while (!isButtonPressed()); return true; }
void processAudio(AudioBuffer& buffer){ float a = getParameterValue(PARAMETER_A); int b = getParameterValue(PARAMETER_B)*127; int c = getParameterValue(PARAMETER_C)*127; if(isButtonPressed(PUSHBUTTON)){ voice.startNote(b, c); }else if(isButtonPressed(RED_BUTTON)){ voice.stopNote(true); } /* if(a > 0.8){ voice.startNote(b, c); }else if(a < 0.1){ voice.stopNote(false); }else if(a < 0.3){ voice.stopNote(true); } */ voice.renderNextBlock(buffer); }
/** * Simulates a "mouse button release". Used in circumstances * where the surface is unpressed without user input. * @param state Pointer to running state. */ void InteractiveSurface::unpress(State *state) { if (isButtonPressed()) { _buttonsPressed = 0; SDL_Event ev; ev.type = SDL_MOUSEBUTTONUP; ev.button.button = SDL_BUTTON_LEFT; Action a = Action(&ev, 0.0, 0.0, 0, 0); mouseRelease(&a, state); } }
void cmd_but_test(void) { SerialUSB.println("Press the button to test. Press any key to stop."); pinMode(BOARD_BUTTON_PIN, INPUT); while (!SerialUSB.available()) { if (isButtonPressed()) { uint32 tstamp = millis(); SerialUSB.print("Button press detected, timestamp: "); SerialUSB.println(tstamp); } } SerialUSB.read(); }
int AvcMenu::buttonPressed () { if (isButtonPressed(MENU_SCROLL_PIN)) { for (int ii = 1; ii < 4; ii++) { bounce[ii-1] = bounce[ii]; } bounce[3] = MENU_SCROLL_PIN; } else if (isButtonPressed(MENU_SELECT_PIN)) { for (int ii = 1; ii < 4; ii++) { bounce[ii-1] = bounce[ii]; } bounce[3] = MENU_SELECT_PIN; } else { for (int ii = 1; ii < 4; ii++) { bounce[ii-1] = bounce[ii]; } bounce[3] = 0; } if (bounce[0] != bounce[3] && bounce[1] == bounce[3] && bounce[2] == bounce[3]) { return bounce[3]; } return 0; }
int main(void) { initLEDs(); initButtons(); while (1) { if (isButtonPressed(SB2)) { turnOffLEDs(); } else { checkLEDsSettingButtons(); } _delay_ms(50); } return 0; }
void buttonSM(ButtonData *data) { switch (data->state) { case RELEASE : if (isButtonPressed() == 1) { msg = CHANGE_MODE; // Pass the message to LED data->state = PRESS ; } break ; case PRESS : if (isButtonPressed() == 0) data->state = RELEASE ; break ; default : //printf("Error : unknown state encountered in buttonSM : %d\n",data->state); break ; } }
void processAudio(AudioBuffer& buffer){ float tone = 60*powf(2, getParameterValue(PARAMETER_A)*6); float decay = getParameterValue(PARAMETER_B); float fc = getParameterValue(PARAMETER_C)*0.498+0.01; float fm = getParameterValue(PARAMETER_D); FloatArray left = buffer.getSamples(LEFT_CHANNEL); FloatArray right = buffer.getSamples(RIGHT_CHANNEL); cymbal[0]->setFrequency(tone); cymbal[0]->setFilter(fc); cymbal[0]->setDecay(decay); cymbal[0]->setFmAmount(fm); cymbal[1]->setFrequency(tone); cymbal[1]->setFilter(fc); cymbal[1]->setDecay(decay/2); cymbal[1]->setFmAmount(fm); if(buttonstate != isButtonPressed(PUSHBUTTON)){ buttonstate = isButtonPressed(PUSHBUTTON); cymbal[0]->gate(buttonstate, getSamplesSinceButtonPressed(PUSHBUTTON)); cymbal[1]->trigger(buttonstate, getSamplesSinceButtonPressed(PUSHBUTTON)); } cymbal[0]->getSamples(left); cymbal[1]->getSamples(right); }
/** * Simulates a "mouse button release". Used in circumstances * where the surface is unpressed without user input. * @param state Pointer to running state. */ void InteractiveSurface::unpress(State *state) { if (isButtonPressed()) { for (int i = 0; i <= NUM_BUTTONS; ++i) { _buttonsPressed[i] = false; } SDL_Event ev; ev.type = SDL_MOUSEBUTTONUP; ev.button.button = SDL_BUTTON_LEFT; Action a = Action(&ev, 0.0, 0.0); mouseRelease(&a, state); } }
void processAudio(AudioBuffer& buffer){ float tone = 20*powf(2, getParameterValue(PARAMETER_A)*4); float decay = getParameterValue(PARAMETER_B)*100; float c = getParameterValue(PARAMETER_C); float level = getParameterValue(PARAMETER_D)*2; drum[0]->setDecay(decay); drum[0]->setFrequency(tone); drum[1]->setDecay(decay*2); drum[1]->setFrequency(tone*2); drum[1]->setSnap(c); FloatArray left = buffer.getSamples(LEFT_CHANNEL); FloatArray right = buffer.getSamples(RIGHT_CHANNEL); if(isButtonPressed(PUSHBUTTON) != buttonstate){ buttonstate = isButtonPressed(PUSHBUTTON); if(buttonstate){ drum[0]->trigger(); drum[1]->trigger(); } } drum[0]->getSamples(left); drum[1]->getSamples(right); left.multiply(level); right.multiply(level); }
/** * Sets the button as the pressed button if it's part of a group, * and inverts the colors when pressed. * @param action Pointer to an action. * @param state State that the action handlers belong to. */ void BattlescapeButton::mousePress(Action *action, State *state) { if (_group != 0) { if (action->getDetails()->button.button == SDL_BUTTON_LEFT) { (*_group)->toggle(false); *_group = this; _inverted = true; } } else if ((_tftdMode || _toggleMode == INVERT_CLICK ) && !_inverted && isButtonPressed() && isButtonHandled(action->getDetails()->button.button)) { _inverted = true; } InteractiveSurface::mousePress(action, state); }
// __attribute__ ((section (".coderam"))) void PatchController::process(AudioBuffer& buffer){ mode = getPatchMode(); if(isButtonPressed(RED_BUTTON)){ mode |= 1; if(red.index != getRedPatchId()){ initialisePatch(RED, getRedPatchId()); return; } }else{ mode &= ~1; if(green.index != getGreenPatchId()){ initialisePatch(GREEN, getGreenPatchId()); return; } } switch(mode){ case SINGLE_GREEN_MODE: case DUAL_GREEN_MODE: green.setParameterValues(parameterValues); green.patch->processAudio(buffer); break; case SINGLE_RED_MODE: case DUAL_RED_MODE: red.setParameterValues(parameterValues); red.patch->processAudio(buffer); break; case SERIES_GREEN_MODE: green.setParameterValues(parameterValues); green.patch->processAudio(buffer); red.patch->processAudio(buffer); break; case SERIES_RED_MODE: red.setParameterValues(parameterValues); green.patch->processAudio(buffer); red.patch->processAudio(buffer); break; case PARALLEL_GREEN_MODE: green.setParameterValues(parameterValues); processParallel(buffer); break; case PARALLEL_RED_MODE: red.setParameterValues(parameterValues); processParallel(buffer); break; } }
/** * Sets the button as the pressed button if it's part of a group, * and inverts the colors when pressed. * @param action Pointer to an action. * @param state State that the action handlers belong to. */ void ImageButton::mousePress(Action *action, State *state) { if (_group != 0) { if (action->getDetails()->button.button == SDL_BUTTON_LEFT) { (*_group)->invert((*_group)->getColor() + 3); *_group = this; invert(_color + 3); } } else if (!_inverted && isButtonPressed() && isButtonHandled(action->getDetails()->button.button)) { _inverted = true; invert(_color + 3); } InteractiveSurface::mousePress(action, state); }
void input_handler(int signal_no){ int buttonStatus = fgetc(driver); if(isButtonPressed(buttonStatus, 0)){ turnEvent(EVENT_MOVE_LEFT); }else if(isButtonPressed(buttonStatus, 1)){ turnEvent(EVENT_MOVE_UP); }else if(isButtonPressed(buttonStatus, 2)){ turnEvent(EVENT_MOVE_RIGHT); }else if(isButtonPressed(buttonStatus, 3)){ turnEvent(EVENT_MOVE_DOWN); }else if(isButtonPressed(buttonStatus, 4)){ turnEvent(EVENT_SHOOT_LEFT); }else if(isButtonPressed(buttonStatus, 5)){ turnEvent(EVENT_SHOOT_UP); }else if(isButtonPressed(buttonStatus, 6)){ turnEvent(EVENT_SHOOT_RIGHT); }else if(isButtonPressed(buttonStatus, 7)){ turnEvent(EVENT_SHOOT_DOWN); } }
void processAudio(AudioBuffer &buffer){ float rate = getParameterValue(PARAMETER_A); rate = rate*rate*0.005; float a = getParameterValue(PARAMETER_B) - 0.5; if(!triggered && isButtonPressed(PUSHBUTTON)){ x = -6+getParameterValue(PARAMETER_C)*6; triggered = true; }else{ triggered = false; } int size = buffer.getSize(); FloatArray left = buffer.getSamples(LEFT_CHANNEL); FloatArray right = buffer.getSamples(RIGHT_CHANNEL); for(int i=0; i<size; ++i){ left[i] = agnesi(x, a); right[i] = serpentine(x, a); x += rate; } }
void processAudio(AudioBuffer &buffer){ data.numSamps = getParameterValue(PARAMETER_A) * (KP_NUM_SAMPLES-8)+8; data.amp = getParameterValue(PARAMETER_B); data.g = getParameterValue(PARAMETER_C)*(0.5-0.48)+0.48; data.duration = getParameterValue(PARAMETER_D) * KP_NUM_BUFFER; if(isButtonPressed(PUSHBUTTON) && !data.noteOn){ data.noteOn = true; pressButton(RED_BUTTON); } int size = buffer.getSize(); float* left = buffer.getSamples(0); float* right = buffer.getChannels() > 1 ? buffer.getSamples(1) : left; for(int i=0; i<size; ++i){ if(data.noteOn){ if(data.phase > (data.numSamps + 1)){ // if we have filled up our delay line, y(n) = g * (y(n-N) + y( n-(N+1) )) data.pluck[data.phase] = data.g * ( data.pluck[data.phase-data.numSamps] + data.pluck[data.phase - (data.numSamps + 1)] ); }else{ // computing the first N samples, y(n) = x(n) if(data.noiseType == KP_NOISETYPE_GAUSSIAN) data.pluck[data.phase] = data.noise[data.phase]; // use gaussian white noise if(data.noiseType == KP_NOISETYPE_RANDOM) data.pluck[data.phase] = rand()%100000/100000.; // use random noise } left[i] = data.amp * data.pluck[data.phase]; // left channel right[i] = data.amp * data.pluck[data.phase]; // right channel if(data.phase >= data.duration){ // if we have reached the end of our duration data.phase = 0; data.noteOn = false; pressButton(GREEN_BUTTON); }else{ data.phase++; } }else{ left[i] = right[i] = 0; } } }
void loop() { volatile int i = 0; toggleLED(); // An artificial delay for(i = 0; i < 150000; i++) ; if (isButtonPressed()) { if (disable) { systick_disable(); SerialUSB.println("Disabling SysTick"); } else { SerialUSB.println("Re-enabling SysTick"); systick_enable(); } disable = !disable; } SerialUSB.println(millis()); }
int main() { uchar i; cli(); DDRD &= ~(_BV(BUTTON_A) | _BV(BUTTON_B) | _BV(BUTTON_C) | _BV(BUTTON_D) | _BV(BUTTON_MAX) | _BV(BUTTON_MIN)); PORTD |= (_BV(BUTTON_A) | _BV(BUTTON_B) | _BV(BUTTON_C) | _BV(BUTTON_D) | _BV(BUTTON_MAX) | _BV(BUTTON_MIN)); usbInit(); usbDeviceDisconnect(); // enforce re-enumeration for(i = 0; i<250; i++) { // wait 500 ms //wdt_reset(); // keep the watchdog happy _delay_ms(2); } usbDeviceConnect(); sei(); // Enable interrupts after re-enumeration while(1) { usbPoll(); reportBuffer.aileron = map(read_adc(AILERON), 0, 1024, 255, 0); reportBuffer.elevator = map(read_adc(ELEVATOR), 0, 1024, 0, 255); reportBuffer.rudder = map(read_adc(RUDDER), 0, 1024, 0, 255); reportBuffer.throttle = map(read_adc(THROTTLE), 0, 1024, 0, 255); reportBuffer.thumbstickHorizontal = map(read_adc(THUMB_HORIZONTAL), 0, 1024, 0, 255); reportBuffer.thumbstickVertical = map(read_adc(THUMB_VERTICAL), 0, 1024, 0, 255); reportBuffer.buttonStates = 0x00; if (isButtonPressed(BUTTON_A)) { reportBuffer.buttonStates |= _BV(0); } if (isButtonPressed(BUTTON_B)) { reportBuffer.buttonStates |= _BV(1); } if (isButtonPressed(BUTTON_C)) { reportBuffer.buttonStates |= _BV(2); } if (isButtonPressed(BUTTON_D)) { reportBuffer.buttonStates |= _BV(3); } if (isButtonPressed(BUTTON_MAX)) { reportBuffer.buttonStates |= _BV(4); } if (isButtonPressed(BUTTON_MIN)) { reportBuffer.buttonStates |= _BV(5); } while (!usbInterruptIsReady()) { usbPoll(); //wdt_reset(); } usbSetInterrupt((unsigned char *)(&reportBuffer), sizeof(reportBuffer)); } return 0; }