Move sketch to appropriately named subfolder

The Arduino IDE requires that a sketch be located in a folder of the same name. Although the name of the repository does match the sketch name, when GitHub's popular Clone or download > Download ZIP feature is used to download the contents of a repository the branch/release/commit name is appended to the folder name, causing a mismatch.

When opening a file that does not meet this sketch/folder name matching requirement the Arduino IDE presents a dialog:

The file "TWANG32.ino" needs to be inside a sketch folder named "TWANG32".
Create this folder, move the file, and continue?

After clicking "OK" the Arduino IDE currently moves only the file TWANG32.ino to the new folder, leaving behind the other source files. This causes compilation of the sketch to fail:

TWANG32-master\TWANG32\TWANG32.ino:30:23: fatal error: twang_mpu.h: No such file or directory
This commit is contained in:
per1234
2018-04-28 22:40:54 -07:00
parent f2318daa6d
commit 840eab60aa
13 changed files with 0 additions and 0 deletions

99
TWANG32/sound.h Normal file
View File

@@ -0,0 +1,99 @@
/*
* This creates sound tones by outputting a square wave on a DAC pin. The
* volume of the tone is the level of the DAC pin.
*
* The square wave is created by a timer. The timer runs at 2x the freq, because
* it needs to transition high and then low.
*
*
*/
#ifndef SOUND_H
#define SOUND_H
#include "esp32-hal-timer.h";
#define ESP32_F_CPU 80000000 // the speed of the processor
#define AUDIO_INTERRUPT_PRESCALER 80
#define SOUND_TIMER_NO 0
//#define AUDIO_PIN 25
#define MIN_FREQ 20
#define MAX_FREQ 16000
hw_timer_t * sndTimer = NULL;
bool sound_on = true;
bool sound_wave_high = true; // this toggles to create the high/low transitions of the wave
uint8_t sound_volume = 0;
void sound_init(int pin);
bool sound(uint16_t freq, uint8_t volume);
void soundOff();
int dac_pin;
void IRAM_ATTR onSoundTimer()
{
if (sound_on) {
dacWrite(dac_pin, (sound_wave_high?sound_volume:0));
sound_wave_high = ! sound_wave_high;
}
else
dacWrite(dac_pin, 0);
}
void sound_init(int pin){ // pin must be a DAC pin number !! (typically 25 or 26)
dac_pin = pin;
sound_on = false;
pinMode(dac_pin, OUTPUT);
sound_volume = 0;
sndTimer = timerBegin(SOUND_TIMER_NO, AUDIO_INTERRUPT_PRESCALER, true);
timerAttachInterrupt(sndTimer, &onSoundTimer, true);
timerAlarmWrite(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/MIN_FREQ, true); // lower timer freq
timerAlarmEnable(sndTimer);
}
void sound_pause() // this prevents the interrupt from firing ... use during eeprom write
{
if (sndTimer != NULL)
timerStop(sndTimer);
}
void sound_resume() // resume from pause ... after eeprom write
{
if (sndTimer != NULL)
timerRestart(sndTimer);
}
bool sound(uint16_t freq, uint8_t volume){
if (volume == 0) {
soundOff();
return false;
}
if (freq < MIN_FREQ || freq > MAX_FREQ) {
return false;
}
sound_on = true;
sound_volume = volume;
timerAlarmWrite(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/(freq * 2), true);
return true;
}
void soundOff(){
sound_on = false;
sound_volume = 0;
timerAlarmWrite(sndTimer, ESP32_F_CPU/AUDIO_INTERRUPT_PRESCALER/(MIN_FREQ), true); // lower timer freq
}
#endif