Skip to content

Instantly share code, notes, and snippets.

@CalvinLogan
Created May 24, 2021 06:44
Show Gist options
  • Save CalvinLogan/35f0febe23f8f0993687697176149e45 to your computer and use it in GitHub Desktop.
Save CalvinLogan/35f0febe23f8f0993687697176149e45 to your computer and use it in GitHub Desktop.
let y;
let sliderColor;
//where data comes in and we can parse it
//data comes in as a string
function gotData() {
let currentString = serial.readLine();//reading the code, looking for //commas and line breaks
if(currentString.length > 0) {
let sensorArray = split(currentString, ","); //splits string at //delimiter
slider = Number(sensorArray[0]);
potLeft = Number(sensorArray[1]);
potRight = Number(sensorArray[2]);
button = Number(sensorArray[3]);
}
}
function draw() {
background(255,255,255);
var colorLibrary = ["LavenderBlush","LemonChiffon","Lavender","LightCyan","LightPink","PaleTurquoise","Pink","Plum","PowderBlue"];
sliderColor = floor(map(slider, 30, 1023, 0, 8));
thisColor = colorLibrary[sliderColor];
colorString = (String(thisColor));
fill(colorString);
noStroke();
x = map(potLeft,0,1023,0,windowWidth);
y = map(potRight,0,1023,0,windowHeight);
ellipse(x,y,50,50);
serialSend();
}
function serialSend(){
neoByte = String((sliderColor + 1));
if((y <= height/3) && (y >= 0)){
LEDByte = '1';
}else if((y > height/3) && (y < 2*height/3)){
LEDByte = '2';
}else if ((y > 2*height/3) && (y < height)){
LEDByte = '3';
}
serial.write("<");
serial.write(neoByte);
serial.write(",");
serial.write(LEDByte);
serial.write(">");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment