The Arduino version works in nearly the same way as the fundamentals of the CircuitPython version (without the HID and MIDI output). First, set up the Arduino IDE with the Earle Philhower core for use with Pico RP2040 as shown in this guide.

Then, copy the code below and paste it into a new Arduino document. Save it in your Arduino project folder, and then upload it to the Pico, using the settings shown in the guide linked above.

// SPDX-FileCopyrightText: 2022 John Park for Adafruit Industries
// SPDX-License-Identifier: MIT
// Step Switch Party for Pico

// extra library used:
// Bounce2 -- https://github.com/thomasfredericks/Bounce2

#include <Wire.h>
#include <Bounce2.h>


const int num_buttons = 4;
const int led_pins[num_buttons] = {2, 3, 4, 5};
const int button_pins[num_buttons] = {6, 7, 8, 9}; 
Bounce buttons[num_buttons];
bool led_vals[num_buttons];


void setup() {
  Serial.begin(9600);
  delay(1000);
  Serial.println("Step Switch Pico Party");

  for (uint8_t i=0; i< num_buttons; i++){
    buttons[i].attach( button_pins[i], INPUT_PULLUP);
  }

  for (uint8_t i=0; i< num_buttons; i++){
      pinMode(led_pins[i], OUTPUT);
      digitalWrite(led_pins[i], HIGH);
      led_vals[i] = HIGH;
  }
}


void loop() {
  for (uint8_t i=0; i< num_buttons; i++){
    buttons[i].update();
    if( buttons[i].fell()) {
      // do something here, such as send MIDI, change a NeoPixel animation, etc.
      Serial.println(i);
      led_vals[i] = !led_vals[i];
      digitalWrite(led_pins[i], led_vals[i]);
    }
  }
  
}

This guide was first published on Aug 16, 2022. It was last updated on Feb 27, 2024.

This page (Code the Step Switch Party with Arduino) was last updated on Aug 24, 2022.

Text editor powered by tinymce.