<commit_before>/*
 * Buzzer.cpp
 *
 * Created: 7-2-2013 0:22:37
 *  Author: Elco
 */ 
#include "pins.h"
#include "Buzzer.h"
#include <util/delay.h>

#if (alarmPin != 3)
	#error "Check PWM settings when you want to use a different pin for the alarm"
#endif

#if defined(USBCON)
// Arduino Leonardo, the buzzer is on OC0B, but Timer0 is already in use for micros() and millis()
// Do not change anything about the timer, just use the output mode
#define BEEP_ON() bitSet(TCCR0A,COM0B1);
#define BEEP_OFF() bitClear(TCCR0A,COM0B1);

void Buzzer::init(void){
	// set up square wave PWM for buzzer
	pinMode(alarmPin,OUTPUT);
}

#else
// Arduino Uno, the buzzer is on OC2B
#define BEEP_ON() bitSet(TCCR2A,COM2B1);
#define BEEP_OFF() bitClear(TCCR2A,COM2B1);
	
void Buzzer::init(void){
	// set up square wave PWM for buzzer
	pinMode(alarmPin,OUTPUT);
	// Arduino UNO, buzzer is on OC2B
	TCCR2A = (1<<COM2B1) | (1<<WGM22) | (1<<WGM20);
	TCCR2B = (1<<CS21) | (1<<CS20); // prescaler = 32
	OCR2A = 125; // timer top. This value adjusts the frequency.
}
#endif


void Buzzer::beep(uint8_t numBeeps, uint16_t duration){
	for(uint8_t beepCount = 0; beepCount<numBeeps; beepCount++){
		BEEP_ON();
		delay(duration);
		BEEP_OFF();
		if(beepCount < numBeeps - 1){
			delay(duration); // not the last beep
		}		
	}		
}	
	
Buzzer buzzer;<commit_msg>Fixed buzzer on Arduino UNO<commit_after>/*
 * Buzzer.cpp
 *
 * Created: 7-2-2013 0:22:37
 *  Author: Elco
 */ 
#include "pins.h"
#include "Buzzer.h"
#include <util/delay.h>

#if (alarmPin != 3)
	#error "Check PWM settings when you want to use a different pin for the alarm"
#endif

#if defined(USBCON)
// Arduino Leonardo, the buzzer is on OC0B, but Timer0 is already in use for micros() and millis()
// Do not change anything about the timer, just use the output mode
#define BEEP_ON() bitSet(TCCR0A,COM0B1);
#define BEEP_OFF() bitClear(TCCR0A,COM0B1);

void Buzzer::init(void){
	// set up square wave PWM for buzzer
	pinMode(alarmPin,OUTPUT);
}

#else
// Arduino Uno, the buzzer is on OC2B
#define BEEP_ON() bitSet(TCCR2A,COM2B1);
#define BEEP_OFF() bitClear(TCCR2A,COM2B1);
	
void Buzzer::init(void){
	// set up square wave PWM for buzzer
	pinMode(alarmPin,OUTPUT);
	// Arduino UNO, buzzer is on OC2B
	TCCR2A = (1<<COM2B1) | (1<<WGM20);
	TCCR2B = (1<<WGM22) | (1<<CS21) | (1<<CS20); // prescaler = 32
	OCR2A = 125; // timer top. This value adjusts the frequency.
	OCR2B = 62;
}

#endif


void Buzzer::beep(uint8_t numBeeps, uint16_t duration){
	for(uint8_t beepCount = 0; beepCount<numBeeps; beepCount++){
		BEEP_ON();
		delay(duration);
		BEEP_OFF();
		if(beepCount < numBeeps - 1){
			delay(duration); // not the last beep
		}		
	}		
}	
	
Buzzer buzzer;
{'fraction_non_alphanumeric': 0.14052044609665426, 'fraction_numerical': 0.043494423791821564, 'mean_word_length': 4.155172413793103, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6042917', 'n_tokens_mistral': 1228, 'n_tokens_neox': 1100, 'n_words': 307}