#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
int menu = 0;
int potM0 =A1;
int potM1 =A0;
int potM2 =A2;
int var = 0;
int t;
int T = 0;
int bar = 0;
int t2;
int T2 = 0;
int sec = 0;
int t3;
int T3;
int tekst1 =0;
byte Euro[8] = {
0b00110,
0b01001,
0b11110,
0b01000,
0b11110,
0b01001,
0b00110,
0b00000
};
byte Vierkant[8] = {
0b00000,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b00000,
0b00000
};
byte Cirkel[8] = {
0b00000,
0b01110,
0b11111,
0b11111,
0b11111,
0b01110,
0b00000,
0b00000
};
byte Driehoek[8] = {
0b00000,
0b00100,
0b00100,
0b01110,
0b01110,
0b11111,
0b11111,
0b00000
};
//.......................Formule 1............................................................
float a, b, c, r, gr, bo, A, B, C;
float calculatie(float X, float Y, float Z)
{
float R;
gr = X/2;
bo = Y/2;
R = (PI*Z*(sq(gr)+sq(bo)+(gr)*(bo)))/3;
return R;
}
//.......................Formule 2............................................................
float ab, hb, ob, stb, Ab;
float calculatieHoogte(float Xb)
{
float Hb;
stb=Xb/2;
Hb = 1000000/(PI*sq(stb));
return Hb;
}
float calculatieOppervlakte(float Xb)
{
float Ob;
stb=Xb/2;
Ob = 2*PI*stb*(stb+(1000000/(PI*sq(stb))));
return Ob;
}
//.......................Formule 3............................................................
float ac, rc, dc, Ac;
float calculatie(float Xc)
{
float Rc;
dc = ((-7172.00*sq(Xc)+717200.00*Xc+80371225.00)/2209.00);
Rc = (((-143440.00-640.00*Xc)/8836.00)-sqrt(dc))/(-4386.00/2209.00);
return Rc;
}
//.......................Formule 4......................................
float ad, wd, kd, afd, Ad;
float maximaleWrijving(float Xd)
{
float Wd;
afd=Xd/100.00;
Wd = 313.92-(533.664/sqrt(16.00+sq(afd)));
return Wd;
}
float horizontaleKracht(float Xd)
{
float Kd;
afd=Xd/100.00;
Kd = (333.54*afd)/sqrt(16.00+sq(afd));
return Kd;
}
//...............Formule 5..........................................
float ae, be, ce, re, Ae, Be, Ce;
float calculatiee(float Xe, float Ye, float Ze)
{
float Re;
float dte = 0.1;
float ge = 9810;
while (Ze>0) {
Ze=Ze-(sq(Xe)/sq(Ye))*dte*sqrt(2*ge*Ze);
Re = Re+dte;
}
return Re;
}
//..........................Eigen opdracht........................
float af, bf, cf, lf, kf, kpf, rhof, oppf, diaf, Af, Bf, Cf;
float calculatief(float Xf, float Yf, float Zf)
{
float Lf;
if (Zf==0) {
diaf = 1.75/1000.00;
oppf=0.25*PI*sq(diaf);
}
else {
diaf = 2.85/1000;
oppf=0.25*PI*sq(diaf);
}
if (Xf==0) {
rhof = 1240.00;
Lf = (Yf/1000.00)/(rhof*oppf);
}
else if (Xf==1) {
rhof = 1010.00;
Lf = (Yf/1000.00)/(rhof*oppf);
}
else {
rhof = 1270.00;
Lf = (Yf/1000.00)/(rhof*oppf);
}
return Lf;
}
float calculatiePrijsf(float Xf, float Yf)
{
float Kf;
if (Xf==0) {
kpf = 26.33;
Kf = (Yf/1000.00)*kpf;
}
else if (Xf==1) {
kpf = 32.00;
Kf = (Yf/1000.00)*kpf;
}
else {
kpf = 28.60;
Kf = (Yf/1000.00)*kpf;
}
return Kf;
}
//Welkom tekst
void scrolling_loop1()
{
String text = "Schuif alle sliders naar omhoog om naar de volgende formule te gaan";
int i, j=0;
for (i =0; i<text.length(); i++)
{
if(i<19)
{
lcd.setCursor(i,1);
lcd.print(text.charAt(i));
delay(150);
}
else
{
for(i=20;i<text.length();i++)
{
j++;
lcd.setCursor(0,1);
lcd.print(text.substring(j,j+20));
delay(250);
}
}
}
}
void scrolling_loop2()
{
String text = "Schuif alle sliders naar omlaag om terug naar de vorige formule te gaan";
int i, j=0;
for (i =0; i<text.length(); i++)
{
if(i<19)
{
lcd.setCursor(i,1);
lcd.print(text.charAt(i));
delay(150);
}
else
{
for(i=20;i<text.length();i++)
{
j++;
lcd.setCursor(0,1);
lcd.print(text.substring(j,j+20));
delay(250);
}
}
}
}
void scrolling_loop3()
{
String text = "Het volume van een afgeknotte kegel";
int i, j=0;
for (i =0; i<text.length(); i++)
{
if(i<19)
{
lcd.setCursor(i,2);
lcd.print(text.charAt(i));
delay(150);
}
else
{
for(i=20;i<text.length();i++)
{
j++;
lcd.setCursor(0,2);
lcd.print(text.substring(j,j+20));
delay(250);
}
}
}
}
void scrolling_loop4()
{
String text = "Cilindrisch volume verpakking";
int i, j=0;
for (i =0; i<text.length(); i++)
{
if(i<19)
{
lcd.setCursor(i,2);
lcd.print(text.charAt(i));
delay(150);
}
else
{
for(i=20;i<text.length();i++)
{
j++;
lcd.setCursor(0,2);
lcd.print(text.substring(j,j+20));
delay(250);
}
}
}
}
void scrolling_loop5()
{
String text = " Kabelbaan";
int i, j=0;
for (i =0; i<text.length(); i++)
{
if(i<19)
{
lcd.setCursor(i,2);
lcd.print(text.charAt(i));
delay(150);
}
else
{
for(i=20;i<text.length();i++)
{
j++;
lcd.setCursor(0,2);
lcd.print(text.substring(j,j+20));
delay(250);
}
}
}
}
void scrolling_loop6()
{
String text = " Trekkabel";
int i, j=0;
for (i =0; i<text.length(); i++)
{
if(i<19)
{
lcd.setCursor(i,2);
lcd.print(text.charAt(i));
delay(150);
}
else
{
for(i=20;i<text.length();i++)
{
j++;
lcd.setCursor(0,2);
lcd.print(text.substring(j,j+20));
delay(250);
}
}
}
}
void scrolling_loop7()
{
String text = " Leegstromend vat";
int i, j=0;
for (i =0; i<text.length(); i++)
{
if(i<19)
{
lcd.setCursor(i,2);
lcd.print(text.charAt(i));
delay(150);
}
else
{
for(i=20;i<text.length();i++)
{
j++;
lcd.setCursor(0,2);
lcd.print(text.substring(j,j+20));
delay(250);
}
}
}
}
void scrolling_loop8()
{
String text = " Kosten 3d printen";
int i, j=0;
for (i =0; i<text.length(); i++)
{
if(i<19)
{
lcd.setCursor(i,2);
lcd.print(text.charAt(i));
delay(150);
}
else
{
for(i=20;i<text.length();i++)
{
j++;
lcd.setCursor(0,2);
lcd.print(text.substring(j,j+20));
delay(250);
}
}
}
}
//.......................Formule 5......................................
void setup()
{
Serial.begin(115200);
T = millis();
lcd.init();
lcd.backlight();
lcd.setCursor(4,1);
lcd.print("Welkom in de");
lcd.setCursor(1,2);
lcd.print("Custom calculator!");
delay(2000);
lcd.clear();
//lcd.setCursor(7,0);
//lcd.print("Uitleg");
//scrolling_loop1();
// delay(1000);
//lcd.clear();
//lcd.setCursor(7,0);
//lcd.print("Uitleg");
//scrolling_loop2();
//delay(1000);
//lcd.clear();
}
void loop()
{
potM0 =analogRead(A0);
potM1 =analogRead(A1);
potM2 =analogRead(A2);
t = millis();
t2 = millis();
t3 = millis();
//............Menu ++
if ((var == 0) && (potM0 >=1022) &&(potM1 >=1022)&&(potM2>=1022)){
var ++;
Serial.println("stap 1");
}
if ((var == 1) && (potM0 < 1022)) {
t = millis();
T = (millis() + 2000);
var ++;
Serial.println("stap 2");
}
if((var==2) && (t>= T)){
var = 0;
Serial.println("stap 3");
} else {
t = millis();
}
if ((var == 2) && (potM0 >= 1022)){
var ++;
Serial.println("schakel");
}
if (var == 3){
lcd.clear();
menu++;
tekst1 = 0;
var = 0;
}
//...........Menu --
if ((bar == 0) && (potM0 ==0) && (potM1 ==0) && (potM2 == 0)){
bar ++;
Serial.println("stapb 1");
}
if ((bar == 1) && (potM0 > 0)) {
t2 = millis();
T2 = (millis() + 2000);
bar ++;
Serial.println("stapb 2");
}
if((bar==2) && (t2>= T2)){
bar = 0;
Serial.println("stapb 3");
} else {
t2 = millis();
}
if ((bar == 2) && (potM0 ==0)){
bar ++;
Serial.println("schakelb");
}
if (bar == 3){
lcd.clear();
menu--;
tekst1 = 0;
bar = 0;
}
//.........Secret menu
if ((sec == 0) && (potM0 == 0) && (potM1 >= 1022) && (potM2 == 0)){
sec ++;
Serial.println("stap secret 1");
}
if ((sec == 1) && (potM1 == 0)) {
t3 = millis();
T3 = (millis() + 5000);
sec ++;
Serial.println("stap secret 2");
}
if((sec==2) && (t3>= T3)){
sec = 0;
Serial.println("stapb 3");
} else {
t3 = millis();
}
if ((sec == 2) && (potM0 >= 1022)){
sec ++;
Serial.println("schakelb");
}
if (sec == 3){
lcd.clear();
menu = 10;
tekst1 = 0;
bar = 0;
}
//.......................Formule 1............................................................
if(menu==-1){
menu =0;
}
if (menu==0){
if(tekst1==0){
lcd.setCursor(5,1);
lcd.print("Formule 1");
scrolling_loop3();
delay(2000);
lcd.clear();
tekst1++;
}
a = map(analogRead(A0), 0, 1023, 0, 55);
lcd.createChar(0, Vierkant);
lcd.setCursor(0,0);
lcd.write((byte)0);
lcd.setCursor(2,0);
lcd.print("Diameter1=");
lcd.print(a,0);
lcd.setCursor(16,0);
lcd.print(" cm");
b = map(analogRead(A1), 0, 1023, 0, 25);
lcd.createChar(1, Cirkel);
lcd.setCursor(0,1);
lcd.write((byte)1);
lcd.setCursor(2,1);
lcd.print("Diameter2=");
lcd.print(b,0);
lcd.setCursor(16,1);
lcd.print(" cm");
c = map(analogRead(A2), 0 , 1023, 0, 100);
lcd.createChar(2, Driehoek);
lcd.setCursor(0,2);
lcd.write((byte)2);
lcd.setCursor(2,2);
lcd.print("Hoogte=");
lcd.print(c,0);
lcd.setCursor(16,2);
lcd.print(" cm");
r = calculatie(a,b,c);
lcd.setCursor(2,3);
lcd.print("Vol.=");
lcd.print(r,2);
lcd.setCursor(17,3);
lcd.print("cm2");
A = a;
B = b;
C = c;
a = map(analogRead(A0), 0, 1023, 0, 55);
if (a != A)
{
lcd.setCursor(12,0);
lcd.print(" ");
lcd.setCursor(12,0);
lcd.print(16,0);
//lcd.print(" cm");
r = calculatie(a,b,c);
lcd.setCursor(9,3);
lcd.print(" ");
lcd.setCursor(9,3);
lcd.print(r,2);
A = a;
}
b = map(analogRead(A1), 0, 1023, 0, 25);
if (b != B)
{
lcd.setCursor(12,1);
lcd.print(" ");
lcd.setCursor(12,1);
lcd.print(b,0);
//lcd.print(" cm");
r = calculatie(a,b,c);
lcd.setCursor(9,3);
lcd.print(" ");
lcd.setCursor(9,3);
lcd.print(r,2);
B = b;
}
c = map(analogRead(A2), 0, 1023, 0, 100);
if (c != C)
{
lcd.setCursor(9,2);
lcd.print(" ");
lcd.setCursor(9,2);
lcd.print(c,0);
//lcd.print(" cm");
r = calculatie(a,b,c);
lcd.setCursor(9,3);
lcd.print(" ");
lcd.setCursor(9,3);
lcd.print(r,2);
C = c;
}
}
//.......................Formule 2..........................................................
else if (menu==1){
if(tekst1==0){
lcd.setCursor(5,1);
lcd.print("Formule 2");
scrolling_loop4();
delay(2000);
lcd.clear();
tekst1++;
}
ab = map(analogRead(A0), 0, 1023, 75, 125);
lcd.createChar(0, Vierkant);
lcd.setCursor(0,0);
lcd.write((byte)0);
lcd.setCursor(2,0);
lcd.print("Diameter=");
lcd.print(ab,0);
lcd.setCursor(16,0);
lcd.print(" mm");
hb = calculatieHoogte(ab);
lcd.setCursor(2,1);
lcd.print("Hoogte=");
lcd.print(hb,2);
lcd.setCursor(16,1);
lcd.print(" mm");
ob = calculatieOppervlakte(ab);
lcd.setCursor(2,2);
lcd.print("Opp=");
lcd.print(ob,2);
lcd.setCursor(16,2);
lcd.print(" mm2");
Ab = ab;
ab = map(analogRead(A0), 0, 1023, 75, 125);
if (ab != Ab)
{
lcd.setCursor(11,0);
lcd.print(" ");
lcd.setCursor(11,0);
lcd.print(ab,0);
//lcd.print(" mm");
hb = calculatieHoogte(ab);
lcd.setCursor(9,1);
lcd.print(" ");
lcd.setCursor(9,1);
lcd.print(hb,2);
//lcd.print(" mm");
ob = calculatieOppervlakte(ab);
lcd.setCursor(12,2);
lcd.print(" ");
lcd.setCursor(12,2);
lcd.print(ob,2);
Ab = ab;
}
}
//.......................Formule 3.......................................................
else if (menu==2){
if(tekst1==0){
lcd.setCursor(5,1);
lcd.print("Formule 3");
scrolling_loop5();
delay(2000);
lcd.clear();
tekst1++;
}
ac = map(analogRead(A0), 0.00, 1023.00, 0.00, 1000.00);
lcd.createChar(0, Vierkant);
lcd.setCursor(0,0);
lcd.write((byte)0);
lcd.setCursor(2,0);
lcd.print("X = ");
lcd.print(ac/10.00,1);
rc = calculatie(ac/10.00);
lcd.setCursor(2,1);
lcd.print("Y = ");
lcd.print(rc,7);
Ac = ac;
ac = map(analogRead(A0), 0.00, 1023.0, 0.00, 1000.00);
if (ac != Ac)
{
lcd.setCursor(6,0);
lcd.print(" ");
lcd.setCursor(6,0);
lcd.print(ac/10.00,1);
rc = calculatie(ac/10.00);
lcd.setCursor(6,1);
lcd.print(" ");
lcd.setCursor(6,1);
lcd.print(rc,7);
Ac = ac;
}
}
//.......................Formule 4.......................................................
else if (menu==3){
if(tekst1==0){
lcd.setCursor(5,1);
lcd.print("Formule 4");
scrolling_loop6();
delay(2000);
lcd.clear();
tekst1++;
}
ad = map(analogRead(A0), 0.00, 1023.00, 0.00, 500.00);
lcd.createChar(0, Vierkant);
lcd.setCursor(0,0);
lcd.write((byte)0);
lcd.setCursor(2,0);
lcd.print("x = ");
lcd.print(ad,0);
lcd.setCursor(16,0);
lcd.print("cm");
wd = maximaleWrijving(ad);
lcd.setCursor(2,1);
lcd.print("Fmax = ");
lcd.print(wd,2);
lcd.print(" N");
kd = horizontaleKracht(ad);
lcd.setCursor(2,2);
lcd.print("Fhor = ");
lcd.print(kd,2);
lcd.print(" N");
Ad = ad;
ad = map(analogRead(A0), 0.00, 1023.00, 0.00, 500.00);
if (ad != Ad)
{
lcd.setCursor(9,0);
lcd.print(" ");
lcd.setCursor(9,0);
lcd.print(ad,0);
//lcd.print(" cm");
wd = maximaleWrijving(ad);
lcd.setCursor(9,1);
lcd.print(" ");
lcd.setCursor(9,1);
lcd.print(wd,2);
kd = horizontaleKracht(ad);
lcd.setCursor(9,2);
lcd.print(" ");
lcd.setCursor(9,2);
lcd.print(kd,2);
lcd.print(" N");
Ad = ad;
}
}
//.......................Formule 5.......................................................
else if (menu==4){
if(tekst1==0){
lcd.setCursor(5,1);
lcd.print("Formule 5");
scrolling_loop7();
delay(2000);
lcd.clear();
tekst1++;
}
{
ae = map(analogRead(A0), 0, 1023, 5, 50);
lcd.createChar(0, Vierkant);
lcd.setCursor(0,0);
lcd.write((byte)0);
lcd.setCursor(2,0);
lcd.print("Diameter1=");
lcd.print(ae,0);
lcd.setCursor(16,0);
lcd.print("mm");
be = map(analogRead(A1), 0, 1023, 400, 800);
lcd.createChar(1, Cirkel);
lcd.setCursor(0,1);
lcd.write((byte)1);
lcd.setCursor(2,1);
lcd.print("Diameter2=");
lcd.print(be,0);
lcd.setCursor(16,1);
lcd.print("mm");
ce = map(analogRead(A2), 0 , 1023, 500, 1000);
lcd.createChar(2, Driehoek);
lcd.setCursor(0,2);
lcd.write((byte)2);
lcd.setCursor(2,2);
lcd.print("Hoogte=");
lcd.print(ce,0);
lcd.setCursor(16,2);
lcd.print("mm");
lcd.setCursor(2,3);
lcd.print("Tijd=");
re = calculatiee(ae,be,ce);
lcd.print(re,0);
lcd.setCursor(13,3);
lcd.print("sec.");
Ae = ae;
Be = be;
Ce = ce;
}
{
ae = map(analogRead(A0), 0, 1023, 5, 50);
if (ae != Ae)
{
lcd.setCursor(12,0);
lcd.print(" ");
lcd.setCursor(12,0);
lcd.print(a,0);
//lcd.print(" mm");
lcd.setCursor(12,0);
lcd.print(ae,0);
re = calculatiee(ae,be,ce);
lcd.setCursor(7,3);
lcd.print(t,0);
lcd.print(" sec.");
lcd.setCursor(7,3);
lcd.print(" ");
lcd.setCursor(7,3);
lcd.print(re,0);
lcd.setCursor(7,3);
lcd.print(t,0);
lcd.print(" sec.");
Ae = ae;
}
be = map(analogRead(A1), 0, 1023, 400, 800);
if (be != Be)
{
lcd.setCursor(12,1);
lcd.print(" ");
lcd.setCursor(12,1);
lcd.print(be,0);
//lcd.print(" mm");
re = calculatiee(ae,be,ce);
lcd.setCursor(7,3);
lcd.print(" ");
lcd.setCursor(7,3);
lcd.print(re,0);
lcd.print(" sec.");
Be = be;
}
ce = map(analogRead(A2), 0, 1023, 500, 1000);
if (ce != Ce)
{
lcd.setCursor(9,2);
lcd.print(" ");
lcd.setCursor(9,2);
lcd.print(ce,0);
//lcd.print(" mm");
re = calculatiee(ae,be,ce);
lcd.setCursor(7,3);
lcd.print(" ");
lcd.setCursor(7,3);
lcd.print(re,0);
lcd.print(" sec.");
Ce = ce;
}
}
}
else if (menu==5){
if(tekst1==0){
lcd.setCursor(3,1);
lcd.print("Eigen opdracht");
scrolling_loop8();
delay(2000);
lcd.clear();
tekst1++;
}
af = map(analogRead(A0), 0, 1023, 0, 2);
lcd.createChar(0, Vierkant);
lcd.setCursor(0,0);
lcd.write((byte)0);
lcd.setCursor(2,0);
lcd.print("Materiaal=");
if (af==0) {
lcd.print("PLA");
}
else if (af==1) {
lcd.print("ABS");
}
else {
lcd.print("PETG");
}
bf = map(analogRead(A1), 0, 1023, 0, 750);
lcd.createChar(1, Cirkel);
lcd.setCursor(0,1);
lcd.write((byte)1);
lcd.setCursor(2,1);
lcd.print("Gewicht=");
lcd.print(bf,0);
//lcd.print(" g");
cf = map(analogRead(A2), 0 , 1023, 0, 1);
lcd.createChar(2, Driehoek);
lcd.setCursor(0,2);
lcd.write((byte)2);
lcd.setCursor(2,2);
lcd.print("Diameter=");
if (cf==0) {
lcd.print("1.75 mm");
}
else {
lcd.print("2.85 mm");
}
lf = calculatief(af,bf,cf);
lcd.setCursor(2,3);
lcd.print("L=");
lcd.print(lf,2);
lcd.print("m");
kf = calculatiePrijsf(af,bf);
lcd.createChar(3, Euro);
lcd.setCursor(12,3);
lcd.write((byte)3);
lcd.print(kf,2);
Af = af;
Bf = bf;
Cf = cf;
{
af = map(analogRead(A0), 0, 1023, 0, 2);
if (af != Af)
{
lcd.setCursor(12,0);
lcd.print(" ");
lcd.setCursor(12,0);
if (af==0) {
lcd.print("PLA");
}
else if (af==1) {
lcd.print("ABS");
}
else {
lcd.print("PETG");
}
lf = calculatief(af,bf, cf);
lcd.setCursor(4,3);
lcd.print(" ");
lcd.setCursor(4,3);
lcd.print(lf,2);
lcd.print("m");
kf = calculatiePrijsf(af,bf);
lcd.setCursor(13,3);
lcd.print(" ");
lcd.setCursor(13,3);
lcd.print(kf,2);
Af = af;
}
bf = map(analogRead(A1), 0, 1023, 0, 750);
if (bf != Bf)
{
lcd.setCursor(10,1);
lcd.print(" ");
lcd.setCursor(10,1);
lcd.print(bf,0);
lcd.setCursor(14,1);
lcd.print("g");
lf = calculatief(af,bf,cf);
lcd.setCursor(4,3);
lcd.print(" ");
lcd.setCursor(4,3);
lcd.print(lf,2);
lcd.print("m");
kf = calculatiePrijsf(af,bf);
lcd.setCursor(13,3);
lcd.print(" ");
lcd.setCursor(13,3);
lcd.print(kf,2);
Bf = bf;
}
cf = map(analogRead(A2), 0, 1023, 0, 1);
if (cf != Cf)
{
lcd.setCursor(11,2);
lcd.print(" ");
lcd.setCursor(11,2);
if (cf==0) {
lcd.print("1.75 mm");
}
else {
lcd.print("2.85 mm");
}
lf = calculatief(af,bf,cf);
lcd.setCursor(4,3);
lcd.print(" ");
lcd.setCursor(4,3);
lcd.print(lf,2);
lcd.print("m");
Cf = cf;
}
}
}
if (menu == 10){
lcd.setCursor(4,0);
lcd.print("Gemaakt door:");
lcd.setCursor(5,1);
lcd.print("Stefan Kars");
lcd.setCursor(1,2);
lcd.print("Camile Zaadnoordijk");
lcd.setCursor(5,3);
lcd.print("Abe Reinsma");
}
}