Skip to content

Instantly share code, notes, and snippets.

@ceiborg
Created July 2, 2020 23:11
Show Gist options
  • Save ceiborg/b6076e9f3a804bc84759a78818b0b7c9 to your computer and use it in GitHub Desktop.
Save ceiborg/b6076e9f3a804bc84759a78818b0b7c9 to your computer and use it in GitHub Desktop.
#include "FastLED.h"
#define NUM_LEDS 7
CRGB leds[NUM_LEDS];
#define PIXELLED 6
float v=0;
float rate= 0.01f;
float c=0;
int button = 3;
void setup() {
Serial.begin (9600);// put your setup code here, to run once:
pinMode (button, INPUT_PULLUP);
FastLED.addLeds<NEOPIXEL, PIXELLED>(leds, NUM_LEDS);
}
void loop() {
c = analogRead (A0);
v += (c-v)* rate;
// Serial.print (c);
// Serial.print (",");
// Serial.println (v);
int sensorMap = constrain (v, 10, 500);
int hueMapped = map (sensorMap, 10, 500, 0, 255);
sendCc(hueMapped/2);
//Serial.println (hueMapped);
for (int i=0;i<NUM_LEDS; i++){
leds[i].setHue(hueMapped);
}
FastLED.show();
delay (1);
}
void sendNote(byte velocity){
sendMidi(0x90, 60, velocity);
}
void sendCc(byte value){
sendMidi(0xB0, 1, value);
}
void sendMidi(byte cmd, byte data1, byte data2){
Serial.write(cmd);
Serial.write(data1);
Serial.write(data2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment