Comments (2)
Heya!
There's good stuff here: you set up the pullups, initialized the overall pin-interrupt (PCIE2), and test for both pins in the ISR. But the confusion here is that both buttons are controlling the same LED.
So when you test BUTTON, it sets the LED, and then the code goes directly to testing BUTTON3. This all happens so fast that you don't even notice that it's working on BUTTON. Try setting/clearing another LED on the other button and you should see that it works.
By the way, I really like this basic approach to learning code -- you build up as simply as possible on the code in the book. This way, a) you make the code your own, and b) you can push it until it breaks and you'll learn something deeper about the way the demo works. Sweet.
from avr-programming.
Thank you Elliot. I am really enjoying your book and would be thrilled to be able to ask you more questions as I go along. I was able to make it work, 2 pins changing the state of the same LED by changing the condition as noted below. I don't know if this is public, but I include it for any other person going through your book as I am. The reason I wanted it this way is because I'm thinking about using an AVR to light up an AUTOART car model, and I need the doors to activate the interior light when the doors open. By the way, do you happen to know if the IRremote.h library can be used along with AVR Studio? If not, do you happen to know a library to use an IR remote with an AVR using C and not C++?
Code:
ISR(PCINT2_vect) { /Run every time there is a change on button... ISR is a macro that denotes a function of interrupt.h/
if (bit_is_set(BUTTON_PIN, BUTTON|BUTTON3)) //PIND, PD2//
{
LED_PORT &= ~(1 << LED1); //PORTB, PB1//
}
else {
LED_PORT |= (1 << LED1); //PORTB, PB1//
}
from avr-programming.
Related Issues (20)
- Chapter 8 Interrupt code and serialScope do not match together
- Unclear statement Chapter 10: only 3 LEDs for hardware PWM when ATmega168PA has 6 HOT 1
- issue building makefile on ubuntu HOT 4
- Windows 10. avr-gcc and avrdude want different MCU strings
- USART.c ATmega16A fix.
- file not found error on first make attempt HOT 3
- When changing Makefile new hex is not generated
- question about makefile
- python code updated to python 3 HOT 4
- download zip fails with a 0kb download
- Lost the ability to receive bytes via USART by Chapter 9! HOT 1
- Issue with Serial Connection on Arduino HOT 2
- littlehacks.org - looks like it's down HOT 2
- compiler warnings atmel328p HOT 1
- avr 328p, crystal and leds HOT 1
- Magical number 3000 in servoWorkout.c (chapter 11)
- magical number 3000 in servoWorkout.c (chapter 11)
- examples 11-1 vs 11-2, prescaling and count speed HOT 1
- Some thoughts
- Incorrect file name
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from avr-programming.