I am new to arduino. Im trying to use rtc3231 to get real time and date and then need to send the data through a rf module. However, i get error during compiling the code. Anyone can help?
// Arduino timer CTC interrupt example
// www.engblaze.com
// avr-libc library includes
#include <avr/io.h>
#include <avr/interrupt.h>
#include <Wire.h>
#include <RTClib.h>
#include <VirtualWire.h>
#define LEDPIN 13
// you must download and install the VirtualWire.h to your hardware/libraries folder
#undef int
#undef abs
#undef double
#undef float
#undef round
RTC_Millis RTC;
//char charnum[10];
//char charnum1[10];
//char charnum2[10];
int seconds = 0;
int i = 0 , j = 0;
int storage [100] ;
int tempvoltage;
int k = 0;
char verify[2];
int precision1;
int precision2;
int precision3;
int mult;
float charf1;
void setup()
{
Serial.begin(9600); // Debugging only
vw_set_ptt_inverted(true); // Required for RX Link Module
vw_setup(2000); // Bits per sec
vw_set_rx_pin(11); // We will be receiving on pin 23 (Mega) ie the RX pin from the module connects to this pin.
vw_rx_start(); // Start the receiver
vw_set_tx_pin(3);
pinMode(LEDPIN, OUTPUT);
// initialize Timer1
cli(); // disable global interrupts
TCCR0A = 0; // set entire TCCR1A register to 0
TCCR0B = 0; // same for TCCR1B
// set compare match register to desired timer count:
OCR0A = 256;
// turn on CTC mode:
TCCR0B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR0B |= (1 << CS10);
TCCR0B |= (1 << CS12);
// enable timer compare interrupt:
TIMSK0 |= (1 << OCIE1A);
// enable global interrupts:
sei();
}
ISR(TIMER0_COMPA_vect)
{
seconds++;
if (seconds == 300)
{
seconds = 0;
readMySensor();
}
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
digitalWrite(13, true); // Flash a light to show received good message
// Message with a good checksum received, dump it.
Serial.print("Got: ");
for (i = 0; i < buflen; i++)
{
verify[1] = buf[i] ;
Serial.println(verify[1]);
}
if (verify[1] == 'k')
{
vw_rx_stop();
for (j = 0; j < k; j++)
{
tempvoltage = storage [j];
// precision1=tempvoltage;
// precision2=tempvoltage;
// precision1 = ((int)(precision1 * 100 ))/ 100.0 ;
// precision2 = ((int)(precision2 * 1000 ))/ 1000.0 ;
// precision3=(precision2-precision1) * 1000;
// if (precision3 >=5)
// {
// precision1=precision1+0.01 ;
// }
serialPrintFloat(tempvoltage);
//Serial.print("Send:");
// Serial.println(precision1);
}
vw_rx_start();
}
digitalWrite(13, false);
}
}
void readMySensor()
{
digitalWrite(13, true);
int sensorValue = analogRead(A0);
float voltage = sensorValue * (5.0 / 1023.0);
Serial.print("sensor:");
Serial.println( voltage );
precision1 = voltage * 1000;
precision2 = voltage * 100;
precision2 = precision2 * 10;
precision1 = precision1 - precision2 ;
if (precision1 >= 5)
{
precision2 = (voltage * 100) + 1;
storage[k] = precision2 ;
}
else
{
storage[k] = voltage * 100 ;
}
// Serial.print("storage[k]:");
// Serial.println( storage[k] );
digitalWrite(13, false);
k++ ;
if (k==100)
{
k = 0;
}
}
void serialPrintFloat( int f ){
int charnum1 = (int)f/100;
int charnum2 = ((int)f/100)*100;
charnum2 = f - charnum2 ;
char msg[24];
sprintf(msg, "%i.%i", charnum1,charnum2);
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx();
}