Skip to main content

How do iI set a constant in void setup() that iI can use in void loop()?

I am new with coding, so iand I was wondering how iI could run something once and define it as a constant. Here is my code:

int sensorValue1 = analogRead(A0);  
int sensorValue2 = analogRead(A1);  
int g0 = 9.81*9.8;  
int h1 = 48;  
int R = 287.06;  
int a = -0.0065;  

void setup() {   
    Serial.begin(9600);  
    int p1 = (1.09512*sensorValue2-22.105)*133.3225;  
    int t1 = (-0.08126*sensorValue1+65.6597)*274.15;  
}

void loop() {
    String t = "Temperature:    ";  
    String tt = " Celsius";  
    String p = "Preassure:    ";  
    String pp = " Pascal";
    float celsius = -0.08126*sensorValue1+65.6597;     
    float kelvin = celsius*274.15;
    float pascal = (1.09512*sensorValue2-22.105)*133.3225;  
    float height = (t1/a)*((pascal/p1)^((a*R)/g0))-1)+h1;  
    Serial.println(t+celsius+tt);  
    Serial.println(p+pascal+pp);  
    Serial.println(kelvin);  
    Serial.println( );  
    Serial.println(height);  
    delay(1000);  
}

How do i set a constant in void setup that i can use in void loop?

I am new with coding, so i was wondering how i could run something once and define it as a constant. Here is my code

int sensorValue1 = analogRead(A0);  
int sensorValue2 = analogRead(A1);  
int g0 = 9.81*9.8;  
int h1 = 48;  
int R = 287.06;  
int a = -0.0065;  

void setup() {   
    Serial.begin(9600);  
    int p1 = (1.09512*sensorValue2-22.105)*133.3225;  
    int t1 = (-0.08126*sensorValue1+65.6597)*274.15;  
}

void loop() {
    String t = "Temperature:    ";  
    String tt = " Celsius";  
    String p = "Preassure:    ";  
    String pp = " Pascal";
    float celsius = -0.08126*sensorValue1+65.6597;     
    float kelvin = celsius*274.15;
    float pascal = (1.09512*sensorValue2-22.105)*133.3225;  
    float height = (t1/a)*((pascal/p1)^((a*R)/g0))-1)+h1;  
    Serial.println(t+celsius+tt);  
    Serial.println(p+pascal+pp);  
    Serial.println(kelvin);  
    Serial.println( );  
    Serial.println(height);  
    delay(1000);  
}

How do I set a constant in setup() that I can use in loop()?

I am new with coding, and I was wondering how I could run something once and define it as a constant. Here is my code:

int sensorValue1 = analogRead(A0);  
int sensorValue2 = analogRead(A1);  
int g0 = 9.81*9.8;  
int h1 = 48;  
int R = 287.06;  
int a = -0.0065;  

void setup() {   
    Serial.begin(9600);  
    int p1 = (1.09512*sensorValue2-22.105)*133.3225;  
    int t1 = (-0.08126*sensorValue1+65.6597)*274.15;  
}

void loop() {
    String t = "Temperature:    ";  
    String tt = " Celsius";  
    String p = "Preassure:    ";  
    String pp = " Pascal";
    float celsius = -0.08126*sensorValue1+65.6597;     
    float kelvin = celsius*274.15;
    float pascal = (1.09512*sensorValue2-22.105)*133.3225;  
    float height = (t1/a)*((pascal/p1)^((a*R)/g0))-1)+h1;  
    Serial.println(t+celsius+tt);  
    Serial.println(p+pascal+pp);  
    Serial.println(kelvin);  
    Serial.println( );  
    Serial.println(height);  
    delay(1000);  
}
added 184 characters in body
Source Link
Majenko
  • 105.9k
  • 5
  • 82
  • 139

I am new with coding, so i was wondering how i could run something once and define it as a constant. Here is my code

int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
int g0 = 9.81*9.8;
int h1 = 48;
int R = 287.06;
int a = -0.0065;

void setup() {
Serial.begin(9600);
int p1 = (1.09512*sensorValue2-22.105)133.3225;
int t1 = (-0.08126
sensorValue1+65.6597)*274.15;
}

void loop() { String t = "Temperature: ";
String tt = " Celsius";
String p = "Preassure: ";
String pp = " Pascal"; float celsius = -0.08126sensorValue1+65.6597;
float kelvin = celsius
274.15; float pascal = (1.09512sensorValue2-22.105)133.3225;
float height = (t1/a)
((pascal/p1)^((a
R)/g0))-1)+h1;
Serial.println(t+celsius+tt);
Serial.println(p+pascal+pp);
Serial.println(kelvin);
Serial.println( );
Serial.println(height);
delay(1000);
}

int sensorValue1 = analogRead(A0);  
int sensorValue2 = analogRead(A1);  
int g0 = 9.81*9.8;  
int h1 = 48;  
int R = 287.06;  
int a = -0.0065;  

void setup() {   
    Serial.begin(9600);  
    int p1 = (1.09512*sensorValue2-22.105)*133.3225;  
    int t1 = (-0.08126*sensorValue1+65.6597)*274.15;  
}

void loop() {
    String t = "Temperature:    ";  
    String tt = " Celsius";  
    String p = "Preassure:    ";  
    String pp = " Pascal";
    float celsius = -0.08126*sensorValue1+65.6597;     
    float kelvin = celsius*274.15;
    float pascal = (1.09512*sensorValue2-22.105)*133.3225;  
    float height = (t1/a)*((pascal/p1)^((a*R)/g0))-1)+h1;  
    Serial.println(t+celsius+tt);  
    Serial.println(p+pascal+pp);  
    Serial.println(kelvin);  
    Serial.println( );  
    Serial.println(height);  
    delay(1000);  
}

I am new with coding, so i was wondering how i could run something once and define it as a constant. Here is my code

int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
int g0 = 9.81*9.8;
int h1 = 48;
int R = 287.06;
int a = -0.0065;

void setup() {
Serial.begin(9600);
int p1 = (1.09512*sensorValue2-22.105)133.3225;
int t1 = (-0.08126
sensorValue1+65.6597)*274.15;
}

void loop() { String t = "Temperature: ";
String tt = " Celsius";
String p = "Preassure: ";
String pp = " Pascal"; float celsius = -0.08126sensorValue1+65.6597;
float kelvin = celsius
274.15; float pascal = (1.09512sensorValue2-22.105)133.3225;
float height = (t1/a)
((pascal/p1)^((a
R)/g0))-1)+h1;
Serial.println(t+celsius+tt);
Serial.println(p+pascal+pp);
Serial.println(kelvin);
Serial.println( );
Serial.println(height);
delay(1000);
}

I am new with coding, so i was wondering how i could run something once and define it as a constant. Here is my code

int sensorValue1 = analogRead(A0);  
int sensorValue2 = analogRead(A1);  
int g0 = 9.81*9.8;  
int h1 = 48;  
int R = 287.06;  
int a = -0.0065;  

void setup() {   
    Serial.begin(9600);  
    int p1 = (1.09512*sensorValue2-22.105)*133.3225;  
    int t1 = (-0.08126*sensorValue1+65.6597)*274.15;  
}

void loop() {
    String t = "Temperature:    ";  
    String tt = " Celsius";  
    String p = "Preassure:    ";  
    String pp = " Pascal";
    float celsius = -0.08126*sensorValue1+65.6597;     
    float kelvin = celsius*274.15;
    float pascal = (1.09512*sensorValue2-22.105)*133.3225;  
    float height = (t1/a)*((pascal/p1)^((a*R)/g0))-1)+h1;  
    Serial.println(t+celsius+tt);  
    Serial.println(p+pascal+pp);  
    Serial.println(kelvin);  
    Serial.println( );  
    Serial.println(height);  
    delay(1000);  
}
Source Link
Andreas
  • 23
  • 1
  • 3

How do i set a constant in void setup that i can use in void loop?

I am new with coding, so i was wondering how i could run something once and define it as a constant. Here is my code

int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
int g0 = 9.81*9.8;
int h1 = 48;
int R = 287.06;
int a = -0.0065;

void setup() {
Serial.begin(9600);
int p1 = (1.09512*sensorValue2-22.105)133.3225;
int t1 = (-0.08126
sensorValue1+65.6597)*274.15;
}

void loop() { String t = "Temperature: ";
String tt = " Celsius";
String p = "Preassure: ";
String pp = " Pascal"; float celsius = -0.08126sensorValue1+65.6597;
float kelvin = celsius
274.15; float pascal = (1.09512sensorValue2-22.105)133.3225;
float height = (t1/a)
((pascal/p1)^((a
R)/g0))-1)+h1;
Serial.println(t+celsius+tt);
Serial.println(p+pascal+pp);
Serial.println(kelvin);
Serial.println( );
Serial.println(height);
delay(1000);
}