Blue: Lowest pressure
Red: Medium pressure
Green: Highest pressure
Setup before the pressure sensor was added
Code
#include <SoftwareSerial.h>SoftwareSerial mySerial(10, 16); // RX, TX
int r = 4;
int g = 3;
int b = 2;
void setup() {
Serial.begin(9600);
pinMode(r,OUTPUT);
pinMode(g,OUTPUT);
pinMode(b,OUTPUT);
mySerial.begin(9600);
}
void loop()
{
while (mySerial.available()){
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (3 / 1023.0);
char test_sensor;
if(voltage>=2){
test_sensor = 'r';
}
else if(voltage>=1){
test_sensor = 'b';
}
else if(voltage>=0){
test_sensor = 'g';
}
char test = mySerial.read();
digitalWrite(r,LOW);
digitalWrite(g,LOW);
digitalWrite(b,LOW);
if(test=='r' or test_sensor == 'r')
{
digitalWrite(r,HIGH);
Serial.println(voltage);
}
else if(test=='b' or test_sensor == 'b')
{
digitalWrite(b,HIGH);
Serial.println(voltage);
}
else
{
digitalWrite(g,HIGH);
Serial.println(voltage);
}
}
}
By: Carolina, Josefine, Lennart, Julius
Inga kommentarer:
Skicka en kommentar