Hi guys, sorry in advance for my poor and if not all what i'm sayng is understandable.
My problem is about making a sort of Dashboard to monitor data in real time recived from arduino, i'm traking distance, sound and ambient lux.
I'm using micophone module, ultrasonic module and photosensor module...
const int trigPin = 9;
const int echoPin = 10;
const int led1 = 11;
const int led2 = 8;
const int pinMIC = 6;
const int PinVibrator = 5;
const int lightPin = A1;
int LightAnalogValue; /* Holds the last analog value */
long duration;
int distance;
const int sampleWindow = 50; // Sample window width in mS (50 mS = 20Hz)
unsigned int sample;
void setup() {
//Connection speed must be same as app.
//Serial.begin(9600);
Serial.begin(57600);
pinMode(PinVibrator, OUTPUT); //Imposto il pin in uscta
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(pinMIC, INPUT);
}
void loop() {
involtReceive();
unsigned long startMillis= millis(); // Start of sample window
unsigned int peakToPeak = 0; // peak-to-peak level
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration*0.034/2;
// Prints the distance on the Serial Monitor
//Serial.print("Distance: ");
//Serial.println(distance);
involtSend(9, distance);
delay(2);
if (distance <= 10) {
digitalWrite(PinVibrator, HIGH);
}
else {
digitalWrite(PinVibrator,LOW);
}
unsigned int signalMax = 0;
unsigned int signalMin = 1024;
// collect data for 50 mS
while (millis() - startMillis < sampleWindow)
{
sample = analogRead(0);
if (sample < 1024) // toss out spurious readings
{
if (sample > signalMax)
{
signalMax = sample; // save just the max levels
}
else if (sample < signalMin)
{
signalMin = sample; // save just the min levels
}
}
}
peakToPeak = signalMax - signalMin; // max - min = peak-peak amplitude
double volts = (peakToPeak * 5.0) / 1024; // convert to volts
int power = volts*10;
analogWrite(led1,power);
analogWrite(led2,power);
int sound = volts*100;
LightAnalogValue = analogRead(lightPin); //Read the voltage from sensor
involtSend(0, sound);
involtSend(1,LightAnalogValue);
I'm using Involt tools in order to output the data from arduino to serial communication but due to mi limited knowledge i can only output data in bar with default color, like in the attachment.
Does anyone know if is possible to create some function that change bar color according to the value that my sensor show ?
HTML CODE
<div class="ard bar A0 range 0-100" style="position:absolute;top:25%;">SOUND</div>
<div class="ard bar A1 range 0-1024" style="position:absolute;top:35%;">LUX</div>
<div class="ard bar V9 range 0-77" style="position:absolute;top:45%;">CM</div>
I know you're not here to solve my problem so i will be patient
really thanks in advance