I am trying to create a time interval that each section displays to the serial monitor and my LCD screen using the millis() command, but I keep getting this error code. I am a newbie with Arduino coding.
/**************************************************************************/
/*!
This is a demo for the Adafruit MCP9808 breakout
----> http://www.adafruit.com/products/1782
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*/
/**************************************************************************/
#include <Wire.h>
#include "Adafruit_MCP9808.h"
// Create the MCP9808 temperature sensor object
Adafruit_MCP9808 tempsensor = Adafruit_MCP9808();
#include <Wire.h>
#include "Adafruit_SI1145.h"
Adafruit_SI1145 uv = Adafruit_SI1145();
// include the library code:
#include <LiquidCrystal.h>
#include <Encoder.h>
Encoder myEnc(2, 3);
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 7, en = 8, d4 = 9, d5 = 10, d6 = 11, d7 = 12;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
unsigned long previousMillisEN = 0;
unsigned long previousMillisTemp = 0;
unsigned long previousMillisEnd = 0;
unsigned long previousMillisUV = 0;
#define temp 1000;
#define UV 1000;
#define ending 5000;
#define R_C 0.031416;
void print_time(unsigned long time_millis);
void setup()
{
Serial.begin(9600);
while (!Serial); //waits for serial terminal to be open, necessary in newer arduino boards.
Serial.println("Adafruit MCP9808");
// Make sure the sensor is found, you can also pass in a different i2c
// address with tempsensor.begin(0x19) for example, also can be left in blank for default address use
// Also there is a table with all addres possible for this sensor, you can connect multiple sensors
// to the same i2c bus, just configure each sensor with a different address and define multiple objects for that
// A2 A1 A0 address
// 0 0 0 0x18 this is the default address
// 0 0 1 0x19
// 0 1 0 0x1A
// 0 1 1 0x1B
// 1 0 0 0x1C
// 1 0 1 0x1D
// 1 1 0 0x1E
// 1 1 1 0x1F
if (!tempsensor.begin(0x18)) {
Serial.println("Couldn't find MCP9808! Check your connections and verify the address is correct.");
while (1);
}
tempsensor.setResolution(0); // sets the resolution mode of reading, the modes are defined in the table bellow:
// Mode Resolution SampleTime
// 0 0.5°C 30 ms
// 1 0.25°C 65 ms
// 2 0.125°C 130 ms
// 3 0.0625°C 250 ms
Serial.begin(9600);
Serial.println("Adafruit SI1145");
if (! uv.begin(0x60)) {
Serial.println("Didn't find Si1145");
while (1);
Serial.println("OK!");
}
Serial.begin(9600);
}
long oldPosition = -999;
void loop()
{
int AnSpeed;
int Speed;
tempsensor.wake(); // wake up, ready to read!
// Read and print out the temperature, also shows the resolution mode used for reading.
Serial.println (tempsensor.getResolution());
float c = tempsensor.readTempC();
if(millis() >= previousMillisTemp + temp){
previousMillisTemp +=temp;
print_time(previousMillisTemp);
Serial.print("Temp: ");
Serial.print(c, 1); Serial.print("*C");
}
tempsensor.shutdown_wake(1); // shutdown MSP9808 - power consumption ~0.1 mikro Ampere, stops temperature sampling
Serial.println("");
if(millis() >= previousMillisUV + UV){
previousMillisUV +=UV;
print_time(previousMillisUV);
Serial.print("Vis: "); Serial.println(uv.readVisible());
Serial.print("IR: "); Serial.println(uv.readIR());
}
// Uncomment if you have an IR LED attached to LED pin!
//Serial.print("Prox: "); Serial.println(uv.readProx());
float UVindex = uv.readUV();
// the index is multiplied by 100 so to get the
// integer index, divide by 100!
UVindex /= 100.0;
Serial.print("UV: "); Serial.println(UVindex);
float newPosition = myEnc.read();
AnSpeed = ((R_C*newPosition)-(R_C*oldPosition))/(currentMillisEN - previousMillisEN);
Speed = AnSpeed*(0.01);
previousMillisEN = currentMillisEN;
if (newPosition != oldPosition) {
oldPosition = newPosition;
Serial.println(newPosition);
}
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
if(millis() >= previousMillisTemp + temp){
previousMillisTemp +=temp;
print_time(previousMillisTemp);
lcd.print("T: "); lcd.print(c, 1); lcd.print("*C");
}
if(millis() >= (previousMillisUV + UV)){
previousMillisUV +=UV;
print_time(previousMillisUV);
lcd.setCursor(0, 1);
lcd.print("UV: "); lcd.print(UVindex);
}
lcd.setCursor(9, 1);
lcd.print("V: "); lcd.print(Speed);
}
This is the error that I get.
Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Uno"
C:\Users\justi\OneDrive\Desktop\ENGG-160\Codes\Weather_Station_Code\Weather_Station_Code.ino: In function 'void loop()':
Weather_Station_Code:102:43: error: expected primary-expression before ')' token
if(millis() >= previousMillisTemp + temp){
^
Weather_Station_Code:111:39: error: expected primary-expression before ')' token
if(millis() >= previousMillisUV + UV){
^
Weather_Station_Code:43:21: error: expected ')' before ';' token
#define R_C 0.031416;
^
C:\Users\justi\OneDrive\Desktop\ENGG-160\Codes\Weather_Station_Code\Weather_Station_Code.ino:128:15: note: in expansion of macro 'R_C'
AnSpeed = ((R_C*newPosition)-(R_C*oldPosition))/(currentMillisEN - previousMillisEN);
^~~
Weather_Station_Code:43:21: error: expected ')' before ';' token
#define R_C 0.031416;
^
C:\Users\justi\OneDrive\Desktop\ENGG-160\Codes\Weather_Station_Code\Weather_Station_Code.ino:128:15: note: in expansion of macro 'R_C'
AnSpeed = ((R_C*newPosition)-(R_C*oldPosition))/(currentMillisEN - previousMillisEN);
^~~
Weather_Station_Code:128:19: error: invalid type argument of unary '*' (have 'float')
AnSpeed = ((R_C*newPosition)-(R_C*oldPosition))/(currentMillisEN - previousMillisEN);
^~~~~~~~~~~
Weather_Station_Code:128:37: error: invalid type argument of unary '*' (have 'long int')
AnSpeed = ((R_C*newPosition)-(R_C*oldPosition))/(currentMillisEN - previousMillisEN);
^~~~~~~~~~~
Weather_Station_Code:130:22: error: 'currentMillisEN' was not declared in this scope
previousMillisEN = currentMillisEN;
^~~~~~~~~~~~~~~
C:\Users\justi\OneDrive\Desktop\ENGG-160\Codes\Weather_Station_Code\Weather_Station_Code.ino:130:22: note: suggested alternative: 'previousMillisEN'
previousMillisEN = currentMillisEN;
^~~~~~~~~~~~~~~
previousMillisEN
Weather_Station_Code:140:43: error: expected primary-expression before ')' token
if(millis() >= previousMillisTemp + temp){
^
Weather_Station_Code:40:16: error: expected ')' before ';' token
#define UV 1000;
^
C:\Users\justi\OneDrive\Desktop\ENGG-160\Codes\Weather_Station_Code\Weather_Station_Code.ino:145:38: note: in expansion of macro 'UV'
if(millis() >= (previousMillisUV + UV)){
^~
Weather_Station_Code:40:16: error: expected ')' before ';' token
#define UV 1000;
^
C:\Users\justi\OneDrive\Desktop\ENGG-160\Codes\Weather_Station_Code\Weather_Station_Code.ino:145:38: note: in expansion of macro 'UV'
if(millis() >= (previousMillisUV + UV)){
^~
Weather_Station_Code:145:40: error: expected primary-expression before ')' token
if(millis() >= (previousMillisUV + UV)){
^
exit status 1
expected primary-expression before ')' token
Please help! I do not understand what I am doing wrong here. Thank you.