Reputation: 19
This is my first time coding. I just learned some stuff from youtube.com and this is the first time I am using that knowledge to write a an arduino sketch for my micro-controller. Please go easy on me.
The problem I am getting is this:
*argument of type "int " is incompatible with parameter of type "uint8_t"
It's in the OUTPUT array declaration.
Error areas 1 and 2
Error area 3
//https://codeshare.io/GA9YDl
#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
bool J5 = 19; //J5 is also an boolerrupt so we are going to be using that as one too.
bool j5state;
//Inputs PULLUPs
bool S3 = 0;
bool S1 = 1;
bool S1state;
bool S3state;
//Momentary PULLUPs
bool J1 = 17;
bool j1state;
//Analog Inputs
int J3in = 2;
int J3state;
//Momentary OUTPUTs
bool J4 = 14;
bool J3out = 18;
//OUTPUTs
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};
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("interrrupt 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.
RSTstate = 1; //Set Reset State to 1 so that the MCU restarts the sketch
}
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(C2, OUTPUT);
pinMode(C3, OUTPUT);
pinMode(C4, OUTPUT);
pinMode(C5, OUTPUT);
Serial.begin(9600);
//First turn off every output
digitalWrite(C1, LOW);
digitalWrite(C2, LOW);
digitalWrite(C3, 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);
}
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);
}
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(C3, 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 into sleep mode and will only wake up if the jack is plugged IN again.
}
}
Upvotes: 1
Views: 893
Reputation: 19
Well here is the modified code. It solved the previous issue (probably because I discarded the array, which is not a solution, but it worked for me).
#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, 11, 13, 4};
int C2[3] = {11, 12, 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.
}
}
Upvotes: 0
Reputation: 144951
The types are incorrect in many of the definitions:
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};
The xxstate
indicators should have type bool
, while the other declarations should have type uint8_t
.
Upvotes: 1