Im using a TEENSY 3.2
im attempting to use the interrupt function (I've never done that before)
my interrupt is to read the falling edge. I want to use the interrupt to return a value back to the loop.
The value is used for setting a PWM output.....
I'm getting some error codes I have never seen.
CODE
const byte dimmerSwitch = 9; // temporary switch for counter. counter is pwm for led dimmer
byte dimmerCount; // track button press
int dimmerValue; // set PWM with counter 0-3
int Dim;
byte ledRyellow = 4; // yellow LED right side
byte ledLyellow = 5; // yellow LED left side
void setup () {
pinMode(dimmerSwitch, INPUT_PULLUP);
pinMode(ledLyellow, OUTPUT);
pinMode(ledLyellow, OUTPUT);
dimmerCount = 1;
attachInterrupt(digitalPinToInterrupt(dimmerSwitch), Dim, FALLING);
}
void loop () {
if (dimmerCount == 3) {
dimmerCount = 0;
}
if (dimmerCount == 0) {
dimmerValue = 40;
}
if (dimmerCount == 1) {
dimmerValue = 115;
}
if (dimmerCount == 2) {
dimmerValue = 255;
}
analogWrite(ledRyellow, dimmerValue);
analogWrite(ledRyellow, dimmerValue);
delay(160);
}
void return Dim () {
dimmerCount++;
}
Error Code
Arduino: 1.8.5 (Windows 10), TD: 1.41, Board: "Teensy 3.2 / 3.1, Serial, 72 MHz, Faster, US English"
dimmer_interupt_test: In function 'void setup()':
dimmer_interupt_test:14: error: invalid conversion from 'int' to 'void (*)()' [-fpermissive]
attachInterrupt(digitalPinToInterrupt(dimmerSwitch), Dim, FALLING);
^
In file included from F:\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:38:0,
from F:\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45,
from F:\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,
from C:\Users\Landon\AppData\Local\Temp\arduino_build_182678\sketch\dimmer_interupt_test.ino.cpp:1:
F:\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:1931:6: note: initializing argument 2 of 'void attachInterrupt(uint8_t, void (*)(), int)'
void attachInterrupt(uint8_t pin, void (*function)(void), int mode);
^
G:\arduino\dimmer_interupt_test\dimmer_interupt_test.ino: At global scope:
dimmer_interupt_test:36: error: expected unqualified-id before 'return'
void return Dim () {
^
invalid conversion from 'int' to 'void (*)()' [-fpermissive]
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
if I could get some guidance on this I would appreciate it, thank you
I guess I'm a special needs kind of person. I apologize, interrupts are new to me.
this is what i have now
ERROR CODE
Arduino: 1.8.5 (Windows 10), TD: 1.41, Board: "Teensy 3.2 / 3.1, Serial, 72 MHz, Faster, US English"
SIX:65: error: 'void Dim()' redeclared as different kind of symbol
void Dim () {
^
G:\arduino\SIX\SIX.ino:8:15: note: previous declaration 'volatile byte Dim'
volatile byte Dim; // interupt name
^
SIX: In function 'void setup()':
SIX:33: error: invalid conversion from 'byte {aka unsigned char}' to 'void (*)()' [-fpermissive]
attachInterrupt(digitalPinToInterrupt(dimmerSwitchISR), Dim, FALLING);
^
In file included from F:\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:38:0,
from F:\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45,
from F:\Arduino\hardware\teensy\avr\cores\teensy3/Arduino.h:3,
from C:\Users\Landon\AppData\Local\Temp\arduino_build_402341\sketch\SIX.ino.cpp:1:
F:\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:1931:6: note: initializing argument 2 of 'void attachInterrupt(uint8_t, void (*)(), int)'
void attachInterrupt(uint8_t pin, void (*function)(void), int mode);
^
SIX: In function 'void Dim()':
SIX:65: error: 'void Dim()' redeclared as different kind of symbol
void Dim () {
^
G:\arduino\SIX\SIX.ino:8:15: note: previous declaration 'volatile byte Dim'
volatile byte Dim; // interupt name
^
'void Dim()' redeclared as different kind of symbol
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
PROGRAM CODE
volatile byte dimmerSwitchISR = 9; // temporary switch for counter. counter is pwm for led dimmer
byte dimmerCount; // track button press
int dimmerValue; // set PWM with counter 0-3
volatile byte Dim; // interupt name
byte ledRred = 3; // red LED right side
byte ledRyellow = 4; // yellow LED right side
byte ledLyellow = 5; // yellow LED left side
byte ledLred = 6; // red LED left side
const byte irA = 21; // middle sensor, address selection
const byte irB = 22; // right side sensor, address selection
const byte irC = 23; // left side sensor, address selection
int battSensor = A0; // read battery voltage, pin 14 on teensy
int hotPixleValue; // amount of pixles from sensor that are detecting heat
void setup() {
// put your setup code here, to run once:
// pinMode(dimmerSwitchISR,INPUT_PULLUP);
pinMode(ledRred, OUTPUT);
pinMode(ledRyellow, OUTPUT);
pinMode(ledLyellow, OUTPUT);
pinMode(ledLred, OUTPUT);
pinMode(irA, OUTPUT);
pinMode(irB, OUTPUT);
pinMode(irC, OUTPUT);
dimmerCount = 1;
attachInterrupt(digitalPinToInterrupt(dimmerSwitchISR), Dim, FALLING);
}
void loop() {
// put your main code here, to run repeatedly:
/*if (digitalRead(dimmerSwitch) == LOW){
//dimmerCount++;
}*/
if (dimmerCount == 3) {
dimmerCount = 0;
}
if (dimmerCount == 0) {
dimmerValue = 40;
}
if (dimmerCount == 1) {
dimmerValue = 115;
}
if (dimmerCount == 2) {
dimmerValue = 255;
}
analogWrite(ledLyellow, dimmerValue);
analogWrite(ledLred, dimmerValue);
analogWrite(ledRred, dimmerValue);
analogWrite(ledRyellow, dimmerValue);
delay(160);
}
void Dim () {
dimmerCount++;
}
TolpuddleSartre:
You've got function and a variable called "Dim"
Ah, thank you. I commented out the variable and it compiled. I was probably doing something wrong but I recall the error codes saying it that "Dim" wasn't named... that's why I listed it as a variable.
Thank you all very much, I learned something new today
You are using a Teensy 3.2, which uses a Cortex M4 processor, so the way you set and handle interrupts may be different. None-the-less, here is an example of how to use an interrupt. This example expects an Arduino Uno, but you can try it on your board.
First connect a switch between pin 2 and ground. Hook your board to a serial port on your computer, and load the following sketch:
The built-in LED will turn on and off according to the switch, and the total number of times the switch was thrown will be shown on the serial monitor. The only thing the ISR does is set a variable high or low, depending on the state of the input pin. Everything else happens in the loop() function.