GAMING FUN
Published © GPL3+

Tutorial ( different frequencies using BUZZER + pushbutton

Using 3 pushbuttons two to give different frequencies to the BUZZER while the third one to stop the BUZZER

BeginnerFull instructions provided505
Tutorial ( different frequencies using BUZZER + pushbutton

Things used in this project

Story

Read more

Code

c code

C#
#include <xc.h>
#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
#define buzz PB3
#define button1 PB0
#define button2 PD2
#define button3 PD3




int main (){
	
	DDRB |= (1<<buzz);
	DDRB &= ~(1<<button1);
	DDRD &= ~(1<<button2);
	DDRD &= ~(1<<button3);
	PORTB |= (1 << button1); // pull-up for the three button
	PORTD |= (1 << button2);
	PORTD |= (1 << button3);

	while(1)
	
	{
		while((PIND & (1 << button2)) != 0 && (PIND & (1 << button3)) != 0 && (PINB & (1 << button1)) != 0)//wait untill one of the button to be pressed
		_delay_ms(10);
		
		
		while((PIND & (1 << button2)) != 0 && (PIND & (1 << button3)) != 0)// if button1 is pressed
		{
			PORTB |= (1<<buzz);
			_delay_us(250);
			

			PORTB &= ~(1<<buzz);
			_delay_us(250);
		}
		

		while((PINB & (1 << button1)) != 0 && (PIND & (1 << button3)) != 0) // if button 2 is pressed
		{
			PORTB |= (1<<buzz);
			_delay_us(125);
			

			PORTB &= ~(1<<buzz);
			_delay_us(125);
		}

		while((PINB & (1 << button1)) != 0 && (PIND & (1 << button2)) != 0) // if button 3 is pressed
		{
			PORTB &= ~(1<<buzz);
		}
		





	}
}

Credits

GAMING FUN
3 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.