mega2560 interupt use
Posted: Mon Mar 02, 2020 6:54 pm
hi everyone;
I just did some testing on 2560 and it didn't look too good for some things, ........................
I didn't look at speeduino code too close and maybe there are some nuansses(sp), but if it uses interupts.........
cut and paste code if interested
place wire between 7 and desired interupt
need arduino ide, open monitor
cheers!
void setup() {
// put your setup code here, to run once:
//2, 3, 18, 19, 20, 21 mega2560
//ON PIN 18,falling, goes to blink, on 19,RISING&FALLING, it oscillates between blink&help
//2, 3 seem more stable
//20 seems more stable than 21, 21 oscillates between blink&help
pinMode(20,INPUT);//HALL1
pinMode(21,INPUT);//HALL2
attachInterrupt(digitalPinToInterrupt(20), blink, FALLING);
attachInterrupt(digitalPinToInterrupt(21), help, FALLING);
pinMode(7,OUTPUT);
//CHANGE FREQUENCY PWM
int myEraser = 7; // this is 111 in binary and is used as an eraser.....4B IS PORT4, relates to pin 6,7,8
TCCR4B &= ~myEraser; // this operation (AND plus NOT), set the three bits in TCCR4B to 0
int myPrescaler = 5; // this could be a number in [1 , 6]. In this case, 3 corresponds in binary to 011.
TCCR4B |= myPrescaler; //this operation (OR), replaces the last three bits in TCCR2B with our new value 011
Serial.begin(9600); // open the serial port at 9600 bps:
//conclusion pins 2,3 may be suitable for external interupts
//
}
void loop() {
// put your main code here, to run repeatedly:
analogWrite(7, 127);
}
void blink() {
Serial.println("BLINK");
}
void help() {
Serial.println("help");
}
I just did some testing on 2560 and it didn't look too good for some things, ........................
I didn't look at speeduino code too close and maybe there are some nuansses(sp), but if it uses interupts.........
cut and paste code if interested
place wire between 7 and desired interupt
need arduino ide, open monitor
cheers!
void setup() {
// put your setup code here, to run once:
//2, 3, 18, 19, 20, 21 mega2560
//ON PIN 18,falling, goes to blink, on 19,RISING&FALLING, it oscillates between blink&help
//2, 3 seem more stable
//20 seems more stable than 21, 21 oscillates between blink&help
pinMode(20,INPUT);//HALL1
pinMode(21,INPUT);//HALL2
attachInterrupt(digitalPinToInterrupt(20), blink, FALLING);
attachInterrupt(digitalPinToInterrupt(21), help, FALLING);
pinMode(7,OUTPUT);
//CHANGE FREQUENCY PWM
int myEraser = 7; // this is 111 in binary and is used as an eraser.....4B IS PORT4, relates to pin 6,7,8
TCCR4B &= ~myEraser; // this operation (AND plus NOT), set the three bits in TCCR4B to 0
int myPrescaler = 5; // this could be a number in [1 , 6]. In this case, 3 corresponds in binary to 011.
TCCR4B |= myPrescaler; //this operation (OR), replaces the last three bits in TCCR2B with our new value 011
Serial.begin(9600); // open the serial port at 9600 bps:
//conclusion pins 2,3 may be suitable for external interupts
//
}
void loop() {
// put your main code here, to run repeatedly:
analogWrite(7, 127);
}
void blink() {
Serial.println("BLINK");
}
void help() {
Serial.println("help");
}