Need help with c coding the on-board LED blink with two external interrupters

Ill save you the trouble and paste the homework question and what part of the code I have below.

But the problem is that I have about half of the code working, I just cant figure out the other half.
I am using PD2 and PD3 on my Arduino UNO as the inputs.
I am using two standard three pronged slide switched and I cannot seem to figure out how to get the PD3 to work or the light to stay on when both switches are open. I am also using two 10k ohm resistors between the switches and the pins.

Homework problem:

Implement the following using the external interrupts (INT or PCINT pins) in ATMega328P.
Use two NO switches, call them FAST and SLOW. The on-board LED normally remains OFF when you turn ON the power, reset the Uno board, or open FAST and SLOW. When you close SLOW and open FAST, the on-board LED blinks, 1s ON and 1s OFF. When you close FAST and open SLOW, the on-board LED blinks, 0.1s ON and 0.1s OFF. If you close FAST and SLOW, the on-board LED blinks, 1s ON and 1s OFF.

My incomplete code:

#define F_CPU 16000000L //Specify the MPU clock for the delay
#include <util/delay.h> //delay loop functions
#include <avr/io.h>
#include <avr/interrupt.h> // Allows for interrupt

int main(void)
{
DDRB |=0x20; // Configure PB5 as OUTPUT
DDRD &= 0x2f,0x3f; // Configure PD2 & PD3 as INPUT
SREG |=0x80; // Set Bit 7 in SREG i.e. global interrupts
EIMSK |=0x01; // Enable INT0
EICRA |=0x00; // The low level of INT0 generates an interrupt request
while(1)
{
if (0x2f >> 1)
{
PORTB = PORTB | 0x20; //SET PB5 as ON
_delay_ms(100); //0.1s delay
PORTB = PORTB & 0xdf; //RESET PB5 as ON
_delay_ms(100); //0.1s delay
}
else
{
PORTB = PORTB | 0x20; //SET PB5 as ON
}
}
while(1)
{
if (1 << 0x3f)
{
PORTB = PORTB | 0x20; //SET PB5 as ON
_delay_ms(1000); //1s delay
PORTB = PORTB & 0xdf; //RESET PB5 as ON
_delay_ms(1000); //1s delay
}
else
{
PORTB = PORTB | 0x20; //SET PB5 as ON
}
}
}

My incomplete answer

DDRD &= 0x2f,0x3f;    ?

  if (0x2f >> 1)aka “if (1)”

  if (1 << 0x3f) Oops

Please remember to use code tags when posting code

ATG1221: Ill save you the trouble and paste the homework question and what part of the code I have below.

Trouble? Hmmm.

ATG1221: Implement the following using the external interrupts (INT or PCINT pins) in ATMega328P.

I am afraid that proposal is total nonsense.

It just might be of interest if you tell us what course you are taking and who is responsible for such a palpably insane question. :astonished:

Hang on - I just realised - it's the date, isn't it! :sunglasses:

Honestly I'm running on no sleep and I'm both physically and mentally exhausted. Its an intro to micro-controllers course. I can't figure this out and I know my coding methods are either wrong or weird. I am just asking for help from anyone that can actually teach me better than my professor so I don't fail.

Your sketch would be a lot shorter and simpler if you didn't use interrupts.

Then you can explain to your prof why they're inappropriate.

It has to be in C code so what do you think my sketch should look like?

It'll look a lot shorter than what you've got now.

References would be much appreciated

I don't think you'll need references or pointers.

OK cool. Well I still can't get the program to run properly and have no idea what I am doing wrong. But thanks for the moral boost

You still haven't commented on reply #1

AWOL:
My incomplete answer

DDRD &= 0x2f,0x3f;    ?
supposed to be configuring pins 2 and 3 (or at least that’s what it hints to at in my notes)
  if (0x2f >> 1)aka “if (1)”
yes its supposed to stand for if the pin is greater than one
  if (1 << 0x3f) Oops
same as the last just in a different order which shouldn’t matter (again referred to my notes)
Please remember to use code tags when posting code

also apparently the whole point of the homework is the interrupts

OK.
That clarifies a few things.

You need to go back to your earlier C notes, and read up on what the comma operator does, and the difference between “>>” and “>”, “<<” and “<”, and what reading a pin involves.

I suggest forgetting the homework problem, and concentrate on the basics.

If you are trying to get code to run on an Arduino it will need a setup and loop function. Your code only has a main function.

Look up what these two missing functions do.

What machine are you trying to run this on?

Grumpy_Mike: If you are trying to get code to run on an Arduino it will need a setup and loop function. Your code only has a main function.

Well, no that is a standard way to execute a "C" program where the main() function performs the setup() and then goes into its while(1) loop which executes the loop().

It's just that the setup() and loop() functions are a more organised way of doing it, particularly for a system which is self-contained and does not exit to any other.

But you know all this, Mike. :grinning:

What we are advising, is to learn the usual way of doing it here and use the functions in the Arduino IDE such as digitalWrite and digitalRead since you are indeed doing this on an Arduino UNO. That much would make sense.

As to the absurd and convoluted use of interrupts, we can assist the OP in understanding the number of reasons why they are so palpably inappropriate.