attachPinChangeInterrupt-invalid conversion from 'byte to void

Hello:)
I got a problem with one part of my “simple” code. After debugging I have the warning: In function ‘void setup()’:
invalid conversion from ‘byte {aka unsigned char}’ to 'void. What’s wrong? I can’t find any solution.

int readValue = 0;
int time1 = 0;
int x = 0;
volatile byte zO;
const int getImp = 8;
int time = 0;
#include “PinChangeInterrupt.h”
void setup()
{
pinMode(8, OUTPUT);
pinMode(7, INPUT_PULLUP);
attachPinChangeInterrupt(digitalPinToPinChangeInterrupt(0), zO, FALLING);
}
void loop(void)
{
void zO();
{
time==5;
return;
}
if (digitalRead(7) == LOW) //
{
digitalWrite(8, HIGH); //work
delay(time1);
}
else {
digitalWrite(8, LOW); //off
}

void loop(void)
  {
  void zO();

Lose the void in front of z0(); - you can;t define new function inside an existing one.

Please read the article about posting in the forum - use code blocks rather than just pasting your code in the text.

You have a variable AND an incorrectly defined function called zO - not allowed.

void loop(void)
{
  void zO();
  {
    time == 5;  //what is this supposed to do ?
    return;   //what are you returning, especially as an ISR cannot return a value
  }

Function defined inside a function

I got a problem with one part of my "simple" code.

No, you have numerous problems in your code. I can say that confidently, without even knowing what it is supposed to do. It is a really obvious, "guess and paste" job.

Sorry, it was stupid :frowning: First I have to explain what I want to do.
Pin number 2 , detection of the falling slope, after zero detection system wait 5ms and take the high signal on pin 8 with the sequence (delays). What is very important? Arduino has to give a signal ( 8 ) only if I push the button on pin number 7. After the process, if I release the button system waits. The loop is close.
How I can realize it?
I've got a problem with logic....

Your best step is to report your code after having fixed the problems already highlighted - remember to use code tags this time, if you don't know how to read the threads at the start of this set of threads.

The only variables that should be declared volatile are normally those that are written to in the ISR, (you don't appear to read any).

Using delay() is generally not a good idea as it stops anything else from happending, use millis() instead - read the articles on how to use millis() for a first explanation.

It would be normal to have a varaible such as volatile bool btnPushed set to true in the ISR and checked in the loop so if set to true you would process the button press and reset btnPushed to false.

I got it to compile for you. I had to take out some code that made no sense. It doesn’t do much but read Pin 7 and write the value to Pin 8. The ISR on Pin 0 doesn’t do anything. Half the variables were never used. Some variables were the wrong type.

#include <PinChangeInterrupt.h>


const int getImp = 8;


unsigned long time1 = 0;


void setup()
{
  pinMode(getImp, OUTPUT);
  pinMode(7, INPUT_PULLUP);
  attachPinChangeInterrupt(digitalPinToPinChangeInterrupt(0), zO, FALLING);
}


void zO()
{
}


void loop()
{
  if (digitalRead(7) == LOW) //
  {
    digitalWrite(getImp, HIGH); //work
    delay(time1);
  }
  else
  {
    digitalWrite(getImp, LOW); //off
  }
}

Thank you for all and especially for you johnwasser. I finish my code and after compilation, I have a fault: exit status 1 expected unqualified-id before ‘{’ token
Probably there is a mistake with pin D2. If somebody has time to compile this code I will be very glad of your help. Comments in the code.

Finalny_v5_-weryf.ang.ino (1.71 KB)

The error message told you where the problem is (or at least where the compiler had noticed things had gone tango uniform), but you chose not to share.

Please remember to use code tags when posting code

void zO()
{
  delayMicroseconds(500);
}
{

Oops

You’d rather remove the code than add code tags? :o

No, I edited this post, never mind...
I checked all possibilities and I can't find this mistake. :angry:

I already pointed out your problem.
(Based on the code you later deleted, not the attached code, which I can’t see)

The mistake is still in the code attached by the OP

void zO()
{
  delayMicroseconds(500);
}
{  //which function is this code block in ?
  sensors.requestTemperatures();
  float x = sensors.getTempCByIndex(0);
  lcd.setCursor(0, 2);
  lcd.print("Temp.transf.");
lcd.setCursor(0, 2);
  lcd.print("Temp.transf.");

Is this supposed to be in interrupt context?

TheMemberFormerlyKnownAsAWOL:

lcd.setCursor(0, 2);

lcd.print("Temp.transf.");

No , after detection of falling scope on pin D2 (0) , wait 500ms and take HIGH on pin 8.

So, does the code compile now?

Not :-\
I still don't know what's wrong.

Take another look at replies #9 and #13

I change this again, now it’s debugging well.

<#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
#include “PinChangeInterrupt.h”
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int odczytanaWartosc = 0;
int teMp = 0;
int czas = 0;
int x = 0;
const int getImp = 8;
unsigned long time1 = 0;
const int button = 7;
float detD2 = 0;//on pin D2 I take 5V to detect falling slope, rectify voltage- unfiltered- is it a good data type?

void setup()
{
lcd.begin(20, 4);
lcd.clear();
lcd.backlight();
sensors.begin();
lcd.setCursor(0, 0);
sensors.getTempCByIndex(0);
pinMode(detD2, INPUT);
pinMode(getImp, OUTPUT);
pinMode(button, INPUT_PULLUP);
attachPinChangeInterrupt(digitalPinToPinChangeInterrupt(0), zO, FALLING);
}
void zO()
{
}
void loop()
{
if (digitalRead (button) == LOW)
{
delayMicroseconds(500);
digitalWrite(getImp, HIGH); //work
}
else
{
digitalWrite(getImp, LOW); //off
}
while (teMp >= 26); //temp.protection
{
digitalWrite(getImp, LOW);
}
{
sensors.requestTemperatures();
float x = sensors.getTempCByIndex(0);
lcd.setCursor(0, 2);
lcd.print(“Temp.transf.”);
lcd.setCursor(0, 3);
lcd.print(" ");
lcd.setCursor(0, 4);
lcd.print(x);

lcd.setCursor(0, 0);
lcd.print(“Impuls time:”);
lcd.setCursor(0, 1);
lcd.print(" ms");
odczytanaWartosc = analogRead(A1);
lcd.setCursor(0, 1);
czas = odczytanaWartosc * (100 / 1023.0);
lcd.print(czas);
delayMicroseconds(500);
digitalWrite(detD2, HIGH);
}
}>