我正在尝试验证并将代码上传到arduino mega 2560,但它给了我一个错误:
Arduino: 1.6.12 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
C:\Users\lenovo\Documents\Arduino\accelerometr_ali\accelerometr_ali.ino:1:19: fatal error: Event.h: No such file or directory
#include <Event.h>
^
compilation terminated.
C:\Program Files (x86)\Arduino\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\lenovo\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10612 -build-path C:\Users\lenovo\AppData\Local\Temp\arduino_build_442935 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\lenovo\Documents\Arduino\accelerometr_ali\accelerometr_ali.ino
C:\Program Files (x86)\Arduino\arduino-builder -compile -logger=machine -hardware C:\Program Files (x86)\Arduino\hardware -tools C:\Program Files (x86)\Arduino\tools-builder -tools C:\Program Files (x86)\Arduino\hardware\tools\avr -built-in-libraries C:\Program Files (x86)\Arduino\libraries -libraries C:\Users\lenovo\Documents\Arduino\libraries -fqbn=arduino:avr:mega:cpu=atmega2560 -ide-version=10612 -build-path C:\Users\lenovo\AppData\Local\Temp\arduino_build_442935 -warnings=none -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -prefs=runtime.tools.avr-gcc.path=C:\Program Files (x86)\Arduino\hardware\tools\avr -verbose C:\Users\lenovo\Documents\Arduino\accelerometr_ali\accelerometr_ali.ino
Using board 'mega' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Using core 'arduino' from platform in folder: C:\Program Files (x86)\Arduino\hardware\arduino\avr
Detecting libraries used...
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\mega" "C:\Users\lenovo\AppData\Local\Temp\arduino_build_442935\sketch\accelerometr_ali.ino.cpp" -o "nul"
"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -flto -w -x c++ -E -CC -mmcu=atmega2560 -DF_CPU=16000000L -DARDUINO=10612 -DARDUINO_AVR_MEGA2560 -DARDUINO_ARCH_AVR "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino" "-IC:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\mega" "C:\Users\lenovo\AppData\Local\Temp\arduino_build_442935\sketch\accelerometr_ali.ino.cpp" -o "C:\Users\lenovo\AppData\Local\Temp\arduino_build_442935\preproc\ctags_target_for_gcc_minus_e.cpp"
C:\Users\lenovo\Documents\Arduino\accelerometr_ali\accelerometr_ali.ino:1:19: fatal error: Event.h: No such file or directory
#include <Event.h>
^
compilation terminated.
exit status 1
Error compiling for board Arduino/Genuino Mega or Mega 2560.
.
代码是给我的合作伙伴,并且在他的笔记本电脑上工作正常。请帮助我们,我明天要介绍它。
这是代码:
#include <Event.h>
#include <Timer.h>
#include <SoftwareSerial.h>
#include <Password.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
#include<stdio.h>
#include<string.h>
#define DEBUG true
//====for gps code=======//
char c;
String response;
//============================//
char key;
char buffer[7];
int i;
SoftwareSerial mySerial(10, 11);
Timer t;
//gprs gps==========================================//
int Powerkey = 9;
//accelerometer=========================================//
#include<Wire.h>
const int MPU_addr = 0x68; // I2C address of the MPU-6050
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
//=====================================================//
#include "pitches.h"
int notes[] = {
NOTE_A4
};
const int buttonPin53 = 53;
int buttonState53 = 0;
LiquidCrystal lcd(44, 45,46, 47, 48, 49, 50);
//LiquidCrystal lcd(12, 8, 7, 5, 4, 3, 2);
Password password = Password( "1234" );
const byte ROWS = 4; // Four rows
const byte COLS = 3; // Three columns
// Define the Keymap
char keys[ROWS][COLS] = {
{'1', '2', '3',},
{'4', '5', '6',},
{'7', '8', '9',},
{'*', '0', ' ',}
};
// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {25, 24, 23, 18}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {28, 27, 26}; //connect to the column pinouts of the keypad
const int buttonPin = 6;
int buttonState = 0;
// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
int t1=0;
int pressed=0;
int afterEvent;
int accident=0;
int pp=0;
void setup() {
pinMode(Powerkey, OUTPUT); // initialize the digital pin as an output.
power();
delay(2000);
//while(1)
//{
for(int g=0; g<3 ; g++){
// sendData( "AT+CGNSINF",1000,DEBUG);
getgps();
delay(1000);
}
//acceleromeeter====================================//
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B); // PWR_MGMT_1 register
Wire.write(0); // set to zero (wakes up the MPU-6050)
Wire.endTransmission(true);
Serial.begin(9600);
//===================================================//
Serial.print("=== AMS ===");
delay(2000);
Serial.print("= WELCOME =");
delay(2000);
Serial.print("System loading...");
Serial.print("Please wait");
delay(3000);
Serial.print("AMS Ready!!");
lcd.print("=== AMS ===");
delay(2000);
lcd.setCursor(0, 1);
lcd.print("= WELCOME =");
delay(2000);
lcd.setCursor(0, 1);
//lcd.clear();
lcd.print("System loading...");
delay(2000);
lcd.setCursor(0, 1);
lcd.print("Please wait");
delay(3000);
lcd.setCursor(0, 1);
// lcd.clear();
lcd.print(" AMS Ready!! ");
delay(3000);
pinMode(buttonPin53, INPUT);
pinMode(buttonPin, INPUT);
lcd.begin(16, 2);
Serial.begin(9600);
mySerial.begin(9600);
if(pp==0){
lcd.clear();
delay(1000);
lcd.print("please enter");
// delay(1000);
lcd.setCursor(0, 1);
lcd.print("your platenumber");
delay(2000);
lcd.clear();
lcd.print("plate number :");
lcd.setCursor(0, 1);
}
keypad.addEventListener(keypadEvent); //add an event listener for this keypad
keypad.setDebounceTime(250);
}
void loop() {
// getgps();
t.update();
// attachInterrupt(5, blink, FALLING);
if(pp==0){
i = 0;
buffer[0] = '\0';
while( i < sizeof(buffer) - 1)
{
key = getChar();
if (key == '*')
{
break;
}
else if ( key != NO_KEY)
{
buffer[i] = key;
i++;
buffer[i]= '\0';
}
}
Serial.println(buffer);
lcd.clear();
lcd.print("success pNb is:");
lcd.setCursor(0, 1);
lcd.print(buffer);
delay(3000);
lcd.clear();
password.reset();
pp=1;
lcd.print("System ready !!!");
lcd.setCursor(0, 1);
}
keypad.getKey();
//acceleromeeter====================================//
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 14, true); // request a total of 14 registers
AcX = Wire.read() << 8 | Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)
AcY = Wire.read() << 8 | Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
AcZ = Wire.read() << 8 | Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
Tmp = Wire.read() << 8 | Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
GyX = Wire.read() << 8 | Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
GyY = Wire.read() << 8 | Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
GyZ = Wire.read() << 8 | Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
Serial.print("AcX = "); Serial.print(AcX);
Serial.print(" | AcY = "); Serial.print(AcY);
Serial.print(" | AcZ = "); Serial.print(AcZ);
Serial.print(" | Tmp = "); Serial.print(Tmp / 340.00 + 36.53); //equation for temperature in degrees C from datasheet
Serial.print(" | GyX = "); Serial.print(GyX);
Serial.print(" | GyY = "); Serial.print(GyY);
Serial.print(" | GyZ = "); Serial.println(GyZ);
delay(3);
if(pp==1){
if (AcX > 8000 || AcX < -8000 || AcY > 7000 || AcY < -7000 || AcZ < -8000 ) {
Serial.print(" == == == == == == = accedent happen == == == == == == == == == = ");
lcd.clear();
lcd.print("Accident happen!");
lcd.setCursor(0, 1);
lcd.print("Sound On");
tone(13, notes[0]);
t1=0;
pressed=0;
accident=1;
afterEvent = t.after(20000, OnceOnlyTask);
// attachInterrupt(5, blink, FALLING);
delay(2000);
}
}
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
password.reset();
lcd.clear();
lcd.print("code reset...");
lcd.setCursor(0, 1);
lcd.print("Enter Again...");
delay(3000);
lcd.clear();
lcd.print("New code :");
lcd.setCursor(0, 1);
}
buttonState53 = digitalRead(buttonPin53);
if (buttonState53 == HIGH) {
pp=0;
lcd.clear();
password.reset();
lcd.print("Plate nb reset..");
lcd.setCursor(0, 1);
lcd.print("Enter Again...");
delay(3000);
lcd.clear();
lcd.print("New Plate nb :");
lcd.setCursor(0, 1);
}
}
void keypadEvent(KeypadEvent eKey) {
switch (keypad.getState()) {
case PRESSED:
lcd.print(eKey);
//Serial.print(" b = ");
Serial.print(eKey);
switch (eKey) {
case ' ': guessPassword(); break;
default:
password.append(eKey);
}
}
}
void guessPassword() {
if(accident==1){
accident=0;
if (password.evaluate()) {
lcd.clear();
if(t1!=1){
pressed = 1;
Serial.print(" valid code");
lcd.print("VALID code ");
delay(2000);
noTone(13);
password.reset(); //resets password after correct entry
delay(600);
lcd.setCursor(0, 1);
lcd.print("Request canceled");
delay(5000);
lcd.clear();
lcd.print("System ready !!!");
lcd.setCursor(0, 1);
}
else{
Serial.print(" Time out");
password.reset();
lcd.print("Time out ");
delay(3000);
lcd.setCursor(0, 1);
lcd.print("Request sended");
delay(3000);
lcd.clear();
lcd.print("System ready !!!");
lcd.setCursor(0, 1);
}
}
else
{
lcd.clear();
lcd.print("INVALID Code ");
password.reset();
delay(2000);
lcd.clear();
lcd.print("System ready !!!");
lcd.setCursor(0, 1);
//resets password after INCORRECT entry
}
}else
{
lcd.clear();
lcd.print("No accident !! ");
delay(2000);
lcd.clear();
lcd.print("System ready !!!");
lcd.setCursor(0, 1);
}
}
void OnceOnlyTask() {
if(t1==0){
if(pressed==0){
Serial.begin(9600);
lcd.clear();
Serial.println("Sending request..");
noTone(13);
lcd.clear();
lcd.print("Sending request..");
// lcd.clear();
lcd.setCursor(0, 1);
lcd.print("data upload...");
delay(2000);
t1=1;
//========gps and http request code=======//
getgps();
//while(1)
//{
for(int g=0; g<5 ; g++){
sendData( "AT+CGNSINF",1000,DEBUG);
delay(1000);
}
// }
String latitude=response.substring(46,54);
delay(1000);
String langitude=response.substring(56,64);
String pl= buffer;
Serial.print(pl);
int tmp0 = Tmp / 340.00 + 36.53;
//String str(buffer);
mySerial.println("AT+CSQ");
delay(100);
ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too.
mySerial.println("AT+CGATT?");
delay(100);
ShowSerialData();
mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
delay(1000);
ShowSerialData();
mySerial.println("AT+SAPBR=3,1,\"APN\",\"CMNET\"");//setting the APN, the second need you fill in your local apn server
delay(5000);
ShowSerialData();
mySerial.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
delay(5000);
ShowSerialData();
mySerial.println("AT+HTTPINIT"); //init the HTTP request
delay(2000);
ShowSerialData();
mySerial.println("AT+HTTPPARA=\"URL\",\"http://amsarabia.000webhostapp.com/write_data.php?platenumber="+pl+"&langitude="+langitude+"&latitude="+latitude+"&temp="+tmp0+"\"");// setting the httppara, the second parameter is the website you want to access
delay(1000);
ShowSerialData();
mySerial.println("AT+HTTPACTION=0");//submit the request
delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
//while(!mySerial.available());
ShowSerialData();
mySerial.println("AT+HTTPREAD");// read the data from the website you access
delay(3000);
ShowSerialData();
mySerial.println("");
delay(1000);
lcd.clear();
// lcd.setCursor(0, 1);
lcd.print("request sended");
delay(3000);
lcd.clear();
lcd.print("System ready !!!");
lcd.setCursor(0, 1);
//========================================//
}
}
}
//=========method for gps and http request=====//
void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}
void getgps(void)
{
sendData( "AT+CGNSPWR=1",1000,DEBUG);
sendData( "AT+CGNSSEQ=RMC",1000,DEBUG);
}
String sendData(String command, const int timeout, boolean debug)
{
response = "";
mySerial.println(command);
long int time = millis();
while( (time+timeout) > millis())
{
while(mySerial.available())
{
c = mySerial.read();
response+=c;
}
}
if(debug)
{
Serial.print(response);
}
return response;
}
//================================//
char getChar()
{
char key = keypad.getKey();
if (key != NO_KEY)
{
return key;
}
else {
return NO_KEY;
}
}
void power(void)
{
digitalWrite(Powerkey, HIGH);
}