make acrylic art code actually work (using tinkercad, parts not in yet)
parent
a404925725
commit
b328a4b00e
@ -1,21 +1,108 @@
|
||||
#include <FastLED.h>
|
||||
int light = 0;
|
||||
int r = 9;
|
||||
int g = 10;
|
||||
int b = 11;
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int ss = 30; // sample size for light sensor
|
||||
int ss = 100; // sample size for light sensor
|
||||
int average = 0;
|
||||
for (int x = 0; x < ss; x++) {
|
||||
average += analogRead(light);
|
||||
delay(1);
|
||||
average += analogRead(light) / 4;
|
||||
delay(3);
|
||||
}
|
||||
average /= ss;
|
||||
String bitIn = "";
|
||||
for(int x = 0; x <9; x++) {
|
||||
bitIn += average >> x;
|
||||
}
|
||||
int a = bitIn.substring(0, 3).toInt();
|
||||
int b = bitIn.substring(3, 6).toInt();
|
||||
int c = bitIn.substring(6, 9).toInt();
|
||||
// set LED strips to c, b, a (in order RGB)
|
||||
CRGB color = CHSV(average, 255, 255);
|
||||
analogWrite(9, color.r);
|
||||
analogWrite(10, color.g);
|
||||
analogWrite(11, color.b);
|
||||
Serial.print("Hue: ");
|
||||
Serial.print(average);
|
||||
Serial.print(", RGB : ");
|
||||
Serial.print(color.r);
|
||||
Serial.print(", ");
|
||||
Serial.print(color.g);
|
||||
Serial.print(", ");
|
||||
Serial.println(color.b);
|
||||
}
|
||||
/* Library free version for regular RGB LEDs (tinkercad), using HSV --> RGB code not by me
|
||||
//#include <FastLED.h>
|
||||
int light = 0;
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
int ss = 20; // sample size for light sensor
|
||||
int average = 0;
|
||||
for (int x = 0; x < ss; x++) {
|
||||
average += analogRead(light) / 4;
|
||||
delay(3);
|
||||
}
|
||||
average /= ss;
|
||||
byte RedLight;
|
||||
byte GreenLight;
|
||||
byte BlueLight;
|
||||
|
||||
// this is the algorithm to convert from RGB to HSV
|
||||
byte h = average;
|
||||
byte s = 255;
|
||||
byte v = 60;
|
||||
h = (h * 192) / 256; // 0..191
|
||||
unsigned int i = h / 32; // We want a value of 0 thru 5
|
||||
unsigned int f = (h % 32) * 8; // 'fractional' part of 'i' 0..248 in jumps
|
||||
|
||||
unsigned int sInv = 255 - s; // 0 -> 0xff, 0xff -> 0
|
||||
unsigned int fInv = 255 - f; // 0 -> 0xff, 0xff -> 0
|
||||
byte pv = v * sInv / 256; // pv will be in range 0 - 255
|
||||
byte qv = v * (256 - s * f / 256) / 256;
|
||||
byte tv = v * (256 - s * fInv / 256) / 256;
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
RedLight = v;
|
||||
GreenLight = tv;
|
||||
BlueLight = pv;
|
||||
break;
|
||||
case 1:
|
||||
RedLight = qv;
|
||||
GreenLight = v;
|
||||
BlueLight = pv;
|
||||
break;
|
||||
case 2:
|
||||
RedLight = pv;
|
||||
GreenLight = v;
|
||||
BlueLight = tv;
|
||||
break;
|
||||
case 3:
|
||||
RedLight = pv;
|
||||
GreenLight = qv;
|
||||
BlueLight = v;
|
||||
break;
|
||||
case 4:
|
||||
RedLight = tv;
|
||||
GreenLight = pv;
|
||||
BlueLight = v;
|
||||
break;
|
||||
case 5:
|
||||
RedLight = v;
|
||||
GreenLight = pv;
|
||||
BlueLight = qv;
|
||||
break;
|
||||
}
|
||||
//CRGB& color = CHSV(average, 255, 255);
|
||||
Serial.print("Hue: ");
|
||||
Serial.print(average);
|
||||
Serial.print(", RGB : ");
|
||||
Serial.print(RedLight);
|
||||
Serial.print(", ");
|
||||
Serial.print(GreenLight);
|
||||
Serial.print(", ");
|
||||
Serial.println(BlueLight);
|
||||
analogWrite(9, RedLight);
|
||||
analogWrite(10, GreenLight);
|
||||
analogWrite(11, BlueLight);
|
||||
}*/
|
||||
|
@ -1,180 +1,206 @@
|
||||
int timeInterval = 0;
|
||||
int analogPin = 5;
|
||||
int drips = 0;
|
||||
float grams = 30;
|
||||
float totgrams = 0;
|
||||
float phSense;
|
||||
float mass = 39.99711;
|
||||
bool titrate = false;
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
if (drips > 0) {
|
||||
grams = grams - (2.333333/20 * drips);
|
||||
}
|
||||
pinMode(2, OUTPUT);
|
||||
pinMode(3, OUTPUT);
|
||||
pinMode(4, OUTPUT);
|
||||
pinMode(9, INPUT); //stream; 2 seconds
|
||||
pinMode(10, OUTPUT);
|
||||
pinMode(11, INPUT); //squirt; 0.5 seconds
|
||||
pinMode(12, INPUT); //drip; 0.01 seconds
|
||||
Serial.begin(9600);
|
||||
digitalWrite(4, LOW); // start extended
|
||||
}
|
||||
void loop() {
|
||||
timeInterval=0;
|
||||
if(digitalRead(7) == 0) {
|
||||
digitalWrite(4, HIGH); // up and down
|
||||
delay(2500);
|
||||
digitalWrite(3, HIGH); // number 3 is spring-loaded
|
||||
delay(1500);
|
||||
digitalWrite(4, LOW);
|
||||
delay(250);
|
||||
motor(255);
|
||||
delay(3000);
|
||||
titrate = true; //true, false for now
|
||||
if(digitalRead(7) == 0 || titrate == false) {
|
||||
Serial.println("CANCELLING");
|
||||
stopmotor();
|
||||
titrate = false;
|
||||
digitalWrite(4, HIGH); // up and down
|
||||
delay(2500);
|
||||
digitalWrite(3, LOW); // number 3 is spring-loaded
|
||||
delay(1500);
|
||||
digitalWrite(4, LOW);
|
||||
delay(500);
|
||||
while(true) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(digitalRead(9) == 0)
|
||||
{
|
||||
motor(255);
|
||||
delay(2000);
|
||||
stopmotor();
|
||||
//timeInterval = 175 * grams;
|
||||
//totgrams = totgrams + grams;
|
||||
}
|
||||
else if(digitalRead(11) == 0 || titrate == true)
|
||||
{
|
||||
takepH();
|
||||
float rate = 1 - (phSense / 7)*(phSense / 7);
|
||||
while (rate > 0 && rate <=1) {
|
||||
motor(255);
|
||||
if(digitalRead(7) == 0) {
|
||||
Serial.println("CANCELLING");
|
||||
titrate = false;
|
||||
stopmotor();
|
||||
digitalWrite(4, HIGH); // up and down
|
||||
delay(1500);
|
||||
digitalWrite(3, LOW); // number 3 is spring-loaded
|
||||
delay(2000);
|
||||
digitalWrite(4, LOW);
|
||||
while(true) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
|
||||
if(rate > 0.8) {
|
||||
rate = rate * 2;
|
||||
}
|
||||
if(phSense > 3) {
|
||||
rate = 0.01;
|
||||
}
|
||||
timeInterval = rate * 175;
|
||||
if (timeInterval < 30) {
|
||||
timeInterval = 15;
|
||||
}
|
||||
totgrams = totgrams + timeInterval / 175;
|
||||
digitalWrite(2, HIGH);
|
||||
delay(timeInterval);
|
||||
digitalWrite(2, LOW);
|
||||
for(int i = 0; i < 10; i += 1){
|
||||
delay(rate * 900);
|
||||
if(digitalRead(7) == 0) {
|
||||
Serial.println("CANCELLING");
|
||||
titrate = false;
|
||||
stopmotor();
|
||||
digitalWrite(4, HIGH); // up and down
|
||||
delay(1500);
|
||||
digitalWrite(3, LOW); // spring-loaded
|
||||
delay(2000);
|
||||
digitalWrite(4, LOW);
|
||||
while(true) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
takepH();
|
||||
rate = 1 - (phSense / 7)*(phSense / 7);
|
||||
delay(125);
|
||||
}
|
||||
Serial.println("done, returning pneumatics to holding point");
|
||||
titrate = false;
|
||||
stopmotor();
|
||||
digitalWrite(4, HIGH); // up and down
|
||||
delay(1500);
|
||||
digitalWrite(3, LOW); // spring-loaded
|
||||
delay(1500);
|
||||
digitalWrite(4, LOW);
|
||||
timeInterval = 0;
|
||||
//timeInterval = 500;
|
||||
//totgrams = totgrams + 2.857143;
|
||||
}
|
||||
else if (digitalRead(12) == 0 || drips > 0)
|
||||
{
|
||||
timeInterval = 15;
|
||||
totgrams = totgrams + 2.333333/20;
|
||||
drips --;
|
||||
}
|
||||
//Serial.print("Time Valve is open = ");
|
||||
//Serial.println(timeInterval);
|
||||
if(timeInterval > 0)
|
||||
{
|
||||
digitalWrite(2, HIGH);
|
||||
delay(timeInterval);
|
||||
digitalWrite(2, LOW);
|
||||
takepH();
|
||||
}
|
||||
delay(50);
|
||||
}
|
||||
float takepH()
|
||||
{
|
||||
int samples = 30;
|
||||
int aRead = 0;
|
||||
for (int i = 0; i < samples ; i++)
|
||||
{
|
||||
aRead += analogRead(analogPin);
|
||||
delay(100);
|
||||
}
|
||||
phSense = 0;
|
||||
float phvolt = 5.0 * aRead/ (1023 * samples); // assuming 5V reference
|
||||
phSense = 14 - phvolt/0.25; // convert voltage to pH
|
||||
phSense = phSense - 1.3;
|
||||
Serial.print("Time Interval = ");
|
||||
Serial.println(timeInterval);
|
||||
Serial.print("Analog in reading: ");
|
||||
Serial.print(aRead/20); // print pH value on serial monitor
|
||||
Serial.print(" - Calculated pH Level: ");
|
||||
Serial.println(phSense, 2); // 1 = one decimal, 2 = two decimals, etc
|
||||
Serial.print("Grams: ");
|
||||
Serial.println(totgrams * 0.87, 4);
|
||||
float molarity = 0.0025 * totgrams * 0.9 / 49.6;
|
||||
Serial.print("Molarity of 20 mL of acid: ");
|
||||
Serial.println(molarity, 10);
|
||||
// removed the /10
|
||||
delay(500);
|
||||
}
|
||||
void motor(int speed) {
|
||||
analogWrite(10, speed);
|
||||
//delay(timerun);
|
||||
//analogWrite(10, 0);
|
||||
}
|
||||
void stopmotor() {
|
||||
analogWrite(10, 0);
|
||||
//delay(timerun);
|
||||
//analogWrite(10, 0);
|
||||
}
|
||||
|
||||
|
||||
#include <controller.h>
|
||||
#include <noise.h>
|
||||
#include <lib8tion.h>
|
||||
#include <colorutils.h>
|
||||
#include <fastspi.h>
|
||||
#include <colorpalettes.h>
|
||||
#include <fastled_progmem.h>
|
||||
#include <fastspi_dma.h>
|
||||
#include <dmx.h>
|
||||
#include <pixeltypes.h>
|
||||
#include <cpp_compat.h>
|
||||
#include <led_sysdefs.h>
|
||||
#include <platforms.h>
|
||||
#include <hsv2rgb.h>
|
||||
#include <fastled_delay.h>
|
||||
#include <pixelset.h>
|
||||
#include <fastspi_ref.h>
|
||||
#include <color.h>
|
||||
#include <FastLED.h>
|
||||
#include <chipsets.h>
|
||||
#include <fastspi_types.h>
|
||||
#include <fastspi_bitbang.h>
|
||||
#include <fastled_config.h>
|
||||
#include <fastpin.h>
|
||||
#include <bitswap.h>
|
||||
#include <power_mgt.h>
|
||||
#include <fastspi_nop.h>
|
||||
|
||||
int timeInterval = 0;
|
||||
int analogPin = 5;
|
||||
int drips = 0;
|
||||
float grams = 30;
|
||||
float totgrams = 0;
|
||||
float phSense;
|
||||
float mass = 39.99711;
|
||||
bool titrate = false;
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
if (drips > 0) {
|
||||
grams = grams - (2.333333/20 * drips);
|
||||
}
|
||||
pinMode(2, OUTPUT);
|
||||
pinMode(3, OUTPUT);
|
||||
pinMode(4, OUTPUT);
|
||||
pinMode(9, INPUT); //stream; 2 seconds
|
||||
pinMode(10, OUTPUT);
|
||||
pinMode(11, INPUT); //squirt; 0.5 seconds
|
||||
pinMode(12, INPUT); //drip; 0.01 seconds
|
||||
Serial.begin(9600);
|
||||
digitalWrite(4, LOW); // start extended
|
||||
}
|
||||
void loop() {
|
||||
timeInterval=0;
|
||||
if(digitalRead(7) == 0) {
|
||||
digitalWrite(4, HIGH); // up and down
|
||||
delay(2500);
|
||||
digitalWrite(3, HIGH); // number 3 is spring-loaded
|
||||
delay(1500);
|
||||
digitalWrite(4, LOW);
|
||||
delay(250);
|
||||
motor(255);
|
||||
delay(3000);
|
||||
titrate = true; //true, false for now
|
||||
if(digitalRead(7) == 0 || titrate == false) {
|
||||
Serial.println("CANCELLING");
|
||||
stopmotor();
|
||||
titrate = false;
|
||||
digitalWrite(4, HIGH); // up and down
|
||||
delay(2500);
|
||||
digitalWrite(3, LOW); // number 3 is spring-loaded
|
||||
delay(1500);
|
||||
digitalWrite(4, LOW);
|
||||
delay(500);
|
||||
while(true) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(digitalRead(9) == 0)
|
||||
{
|
||||
motor(255);
|
||||
delay(2000);
|
||||
stopmotor();
|
||||
//timeInterval = 175 * grams;
|
||||
//totgrams = totgrams + grams;
|
||||
}
|
||||
else if(digitalRead(11) == 0 || titrate == true)
|
||||
{
|
||||
takepH();
|
||||
float rate = 1 - (phSense / 7)*(phSense / 7);
|
||||
while (rate > 0 && rate <=1) {
|
||||
motor(255);
|
||||
if(digitalRead(7) == 0) {
|
||||
Serial.println("CANCELLING");
|
||||
titrate = false;
|
||||
stopmotor();
|
||||
digitalWrite(4, HIGH); // up and down
|
||||
delay(1500);
|
||||
digitalWrite(3, LOW); // number 3 is spring-loaded
|
||||
delay(2000);
|
||||
digitalWrite(4, LOW);
|
||||
while(true) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
|
||||
if(rate > 0.8) {
|
||||
rate = rate * 2;
|
||||
}
|
||||
if(phSense > 3) {
|
||||
rate = 0.01;
|
||||
}
|
||||
timeInterval = rate * 175;
|
||||
if (timeInterval < 30) {
|
||||
timeInterval = 15;
|
||||
}
|
||||
totgrams = totgrams + timeInterval / 175;
|
||||
digitalWrite(2, HIGH);
|
||||
delay(timeInterval);
|
||||
digitalWrite(2, LOW);
|
||||
for(int i = 0; i < 10; i += 1){
|
||||
delay(rate * 900);
|
||||
if(digitalRead(7) == 0) {
|
||||
Serial.println("CANCELLING");
|
||||
titrate = false;
|
||||
stopmotor();
|
||||
digitalWrite(4, HIGH); // up and down
|
||||
delay(1500);
|
||||
digitalWrite(3, LOW); // spring-loaded
|
||||
delay(2000);
|
||||
digitalWrite(4, LOW);
|
||||
while(true) {
|
||||
loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
takepH();
|
||||
rate = 1 - (phSense / 7)*(phSense / 7);
|
||||
delay(125);
|
||||
}
|
||||
Serial.println("done, returning pneumatics to holding point");
|
||||
titrate = false;
|
||||
stopmotor();
|
||||
digitalWrite(4, HIGH); // up and down
|
||||
delay(1500);
|
||||
digitalWrite(3, LOW); // spring-loaded
|
||||
delay(1500);
|
||||
digitalWrite(4, LOW);
|
||||
timeInterval = 0;
|
||||
//timeInterval = 500;
|
||||
//totgrams = totgrams + 2.857143;
|
||||
}
|
||||
else if (digitalRead(12) == 0 || drips > 0)
|
||||
{
|
||||
timeInterval = 15;
|
||||
totgrams = totgrams + 2.333333/20;
|
||||
drips --;
|
||||
}
|
||||
//Serial.print("Time Valve is open = ");
|
||||
//Serial.println(timeInterval);
|
||||
if(timeInterval > 0)
|
||||
{
|
||||
digitalWrite(2, HIGH);
|
||||
delay(timeInterval);
|
||||
digitalWrite(2, LOW);
|
||||
takepH();
|
||||
}
|
||||
delay(50);
|
||||
}
|
||||
float takepH()
|
||||
{
|
||||
int samples = 30;
|
||||
int aRead = 0;
|
||||
for (int i = 0; i < samples ; i++)
|
||||
{
|
||||
aRead += analogRead(analogPin);
|
||||
delay(100);
|
||||
}
|
||||
phSense = 0;
|
||||
float phvolt = 5.0 * aRead/ (1023 * samples); // assuming 5V reference
|
||||
phSense = 14 - phvolt/0.25; // convert voltage to pH
|
||||
phSense = phSense - 1.3;
|
||||
Serial.print("Time Interval = ");
|
||||
Serial.println(timeInterval);
|
||||
Serial.print("Analog in reading: ");
|
||||
Serial.print(aRead/20); // print pH value on serial monitor
|
||||
Serial.print(" - Calculated pH Level: ");
|
||||
Serial.println(phSense, 2); // 1 = one decimal, 2 = two decimals, etc
|
||||
Serial.print("Grams: ");
|
||||
Serial.println(totgrams * 0.87, 4);
|
||||
float molarity = 0.0025 * totgrams * 0.9 / 49.6;
|
||||
Serial.print("Molarity of 20 mL of acid: ");
|
||||
Serial.println(molarity, 10);
|
||||
// removed the /10
|
||||
delay(500);
|
||||
}
|
||||
void motor(int speed) {
|
||||
analogWrite(10, speed);
|
||||
//delay(timerun);
|
||||
//analogWrite(10, 0);
|
||||
}
|
||||
void stopmotor() {
|
||||
analogWrite(10, 0);
|
||||
//delay(timerun);
|
||||
//analogWrite(10, 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue