Generic testing module

I needed a generic testing module which had som inputs and some output. I hacked this emergency button so it had a button, potentiometer and a neopixel ring. Inside I have a esp32. This way I could always have microcontroller test setup in my backpack for experimenting with different elements.

#include "FastLED.h"


// How many leds in your strip?

#define NUM_LEDS 4

#define DATA_PIN 17


// Define the array of leds

CRGB leds[NUM_LEDS];


int analogValue = 0;

int analogPin = 32;

int buttonPin = 25;

boolean buttonValue = false;

boolean buttonValueOld = false;



int brightness = 0;


void setup() {

// put your setup code here, to run once:

Serial.begin(9600);

pinMode(buttonPin, INPUT_PULLUP);

FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

}


void loop() {

// put your main code here, to run repeatedly:


analogValue = analogRead(analogPin);


buttonValue = digitalRead(buttonPin);

if (buttonValue == 1 && buttonValueOld == 0) {

Serial.println("button pressed");


}

buttonValueOld = buttonValue;



int brightness = map(analogValue, 0, 4095, 0, 255); // maps from 0-4095 to scale 0-255


setLedBrightness(brightness);


// debug printing out

Serial.print(analogValue);

Serial.print(",");

Serial.print(brightness);

Serial.print(",");


Serial.println(buttonValue);


}


void setLedBrightness(int value) {

for (int i = 0; i < NUM_LEDS; i = i + 1) {

leds[i] = CRGB( value, 0, 0);

}

FastLED.show();

}