如何解决类型“ int *”的错误参数与类型“ uint8_t”的参数不兼容
这是我第一次编码。我刚刚从youtube.com上学到了一些东西,这是我第一次使用这些知识为我的微控制器编写arduino草图。请放轻松我。
我遇到的问题是:
* “ int ”类型的参数与“ uint8_t”类型的参数不兼容
它在OUTPUT数组声明中。
Error areas 1 and 2 Error area 3
await page.waitForTimeout(5000);
解决方法
在许多定义中,类型都不正确:
bool J5 = 19;
...
bool J1 = 17;
...
int J3in = 2;
int J3state;
bool J4 = 14;
bool J3out = 18;
int C1[4] = {10,11,13,4};
int C2[3] = {11,12,4};
int C3[2] = {10,4};
int C4[1] = {9};
int C5[1] = {8};
xxstate
指示器的类型应为bool
,而其他声明的类型应为uint8_t
。
这是修改后的代码。它解决了先前的问题(可能是因为我丢弃了数组,这不是一个解决方案,但对我有用)。
#include <Arduino.h>
#include <avr/sleep.h> // this AVR library contains the methods that controls the sleep modes
bool RSTstate = 0;
//Inputs and their Variables
int J5 = 19; //J5 is also an boolerrupt so we are going to be using that as one too.
bool j5state;
//Inputs PULLUPs
const int S3 = 0;
const int S1 = 1;
bool S1state;
bool S3state;
//Momentary PULLUPs
const int J1 = 17;
bool j1state;
//Analog Inputs
const int J3in = 2;
int J3state;
//Momentary OUTPUTs
const int J4 = 14;
const int J3out = 18;
//OUTPUTs
const int C123 = 4;
const int C1 = 13;
const int C12 = 11;
const int C13 = 10;
const int C2 = 12;
const int C4 = 9;
const int C5 = 8;
/*
int C1[4] = {10,4};
int C2[3] = {11,4};
int C3[2] = {10,4};
int C4[1] = {9};
int C5[1] = {8};
*/
void goingToSleep() {
sleep_enable(); // enabling sleep mode
attachInterrupt(j5state,wakeUp,LOW); // attaching to boolerrupt J5 (INTERRUPT_PIN) the function wakeUp to be triggered when get LOW signal... Also J5 LOW means plugged IN.
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // setting the sleep mode,in our case full sleep
sleep_cpu(); // activating sleep mode
}
void wakeUp() {
Serial.println("boolerrrupt Fired!"); // print message to serial monitor
sleep_disable(); // disable sleep mode
detachInterrupt(j5state); // removes the boolerrupt from J5
softreset(); //Now needs to reset the mcu as the jack is plugged in.
}
void softreset() {
asm volatile (" jmp 0"); //Just restart the sketch,does not reset the registers etc.
}
void setup() {
pinMode(J5,INPUT);
pinMode(S3,INPUT_PULLUP);
pinMode(S1,INPUT_PULLUP);
pinMode(J1,INPUT);
pinMode(J3in,INPUT);
pinMode(C1,OUTPUT);
pinMode(C12,OUTPUT);
pinMode(C13,OUTPUT);
pinMode(C123,OUTPUT);
pinMode(C2,OUTPUT);
pinMode(C4,OUTPUT);
pinMode(C5,OUTPUT);
Serial.begin(9600);
//First turn off every output
digitalWrite(C1,LOW);
digitalWrite(C12,LOW);
digitalWrite(C123,LOW);
digitalWrite(C13,LOW);
digitalWrite(C2,LOW);
digitalWrite(C4,LOW);
digitalWrite(C5,LOW);
//This is the first phase: To check if the headphone plug is connected or not.
pinMode(J4,OUTPUT);
digitalWrite(J4,LOW);
delay(5);
j5state = digitalRead(J5);
if (j5state == LOW) { //That means that the 3.5mm plug is put in.
//Here the second phase starts where we need to check the connectivity of S1 and S3.
pinMode(J4,INPUT); //Fisrt setup the J4 to INPUT so that it does not boolerface with the Audio.
S1state = digitalRead(S1);
S3state = digitalRead(S3);
if (S1state == HIGH && S3state == LOW) { //This means that Condition 1,2 and 3 applies.
//Here is the 3rd phase starts where we have to check the conditions for C1,C2 and C3
//First C1 where we have to check for J1 and J2 connectivity. J2 is Hardware GND and J1 is mic input which is boolernal PULLUP.
pinMode(J1,INPUT_PULLUP);
delay(5);
j1state = digitalRead(J1);
if (j1state == LOW) {
//This is where the C1 condition is TRUE and is executed
digitalWrite(C1,HIGH);
digitalWrite(C123,HIGH);
digitalWrite(C12,HIGH);
digitalWrite(C13,HIGH);
}
else if (j1state == HIGH) {
//That means C1 is not meeting requirements and thus C2 is now checked
//To check C2 we need to check between J3 and J4 and the easy way to do that is to just check an analog value for J3 to GND.
pinMode(J3in,INPUT);
pinMode(J3out,OUTPUT);
delay(5);
digitalWrite(J3out,HIGH);
delay(5);
J3state = analogRead(J3in);
pinMode(J3out,INPUT);
if (J3state > 15) {
//That means that J3 is not connected to GND. Which means there is a speaker attached. That means C2 is applied.
digitalWrite(C2,HIGH);
digitalWrite(C123,HIGH);
digitalWrite(C12,HIGH);
}
else if (J3state < 15) {
//That means that J3 is directly connected to GND which also means that there is no speaker attached.
//So now C3 is applied.
digitalWrite(C123,HIGH);
digitalWrite(C13,HIGH);
}
else {
Serial.println("ERROR C2,C3");
}
}
else {
Serial.println("ERROR C1");
}
}
else if (S1state == LOW && S3state == HIGH) {
//Now the S1 is turned ON and thus we only need to check Condition 4 (C4) and C5.
//First C4,for C4 we need the connection between J3 and GND. Same method as C2 and C3.
pinMode(J3out,OUTPUT);
delay(5);
digitalWrite(J3out,HIGH);
delay(5);
J3state == analogRead(J3in);
pinMode(J3out,INPUT);
if (J3state > 15) {
//That means J3 is not connected to GND. Which applied C4.
digitalWrite(C4,HIGH);
}
else if (J3state < 15) {
//Now the condition is set to C5
digitalWrite(C5,HIGH);
}
else {
Serial.println("ERROR C4,C5");
}
}
else {
Serial.println("ERROR S1,S3");
}
}
else if (j5state == HIGH) {
goingToSleep();
//This loop is for when there is no jack,the microcontroller can just
//wait for the plug to be inserted. But also in some kind of sleepmode to conserve power.
}
else {
Serial.println("ERROR JACK");
}
}
//All of the above process is done in the setup loop since it does not needs to be repeated. Only run once.
void loop() {
if (RSTstate == 1){
softreset();
}
else {
goingToSleep(); //Once everything is executed succesfully. Here the microcontroller goes boolo sleep mode and will only wake up if the jack is plugged IN again.
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。