Commit ae7b437c authored by yuichitamiya's avatar yuichitamiya
Browse files

workshop ishimura

parent b7431be8
Pipeline #243825 passed with stage
in 41 seconds
#include "Adafruit_FreeTouch.h"
#define SPEAKER 2
Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(A0, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_2 = Adafruit_FreeTouch(A1, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_3 = Adafruit_FreeTouch(A6, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_4 = Adafruit_FreeTouch(A7, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_5 = Adafruit_FreeTouch(A8, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_6 = Adafruit_FreeTouch(A9, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
Adafruit_FreeTouch qt_7 = Adafruit_FreeTouch(A10, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
//int BassTab[] = {1911, 1702, 1516, 1431, 1275, 1136, 1012}; //bass 1~7
//int BassTab[] = { 262, 294, 330, 349, 392, 440, 494}; //bass 1~7
int BassTab[] = { 494, 440, 392, 349, 330, 294, 262}; //bass 1~7
void setup() {
Serial.begin(115200);
pinMode(SPEAKER, OUTPUT);
digitalWrite(SPEAKER, LOW);
// while (!Serial);
Serial.println("FreeTouch test");
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
if (! qt_1.begin())
Serial.println("Failed to begin qt");
if (! qt_2.begin())
Serial.println("Failed to begin qt");
if (! qt_3.begin())
Serial.println("Failed to begin qt");
if (! qt_4.begin())
Serial.println("Failed to begin qt");
if (! qt_5.begin())
Serial.println("Failed to begin qt");
if (! qt_6.begin())
Serial.println("Failed to begin qt");
if (! qt_7.begin())
Serial.println("Failed to begin qt");
}
int qt_Threshold1 = 800;//changed from 850
int qt_Threshold2 = 800;//changed from 850
int qt_Threshold3 = 600;//changed from 850
int qt_Threshold4 = 650;//changed from 850
int qt_Threshold5 = 650;//changed from 850
int qt_Threshold6 = 700;//changed from 850
int qt_Threshold7 = 700;//changed from 850
void loop() {
int qt1 = 0;
int qt2 = 0;
int qt3 = 0;
int qt4 = 0;
int qt5 = 0;
int qt6 = 0;
int qt7 = 0;
qt1 = qt_1.measure();
Serial.print(qt1);
Serial.print(",");
qt2 = qt_2.measure();
Serial.print(qt2);
Serial.print(",");
qt3 = qt_3.measure();
Serial.print(qt3);
Serial.print(",");
qt4 = qt_4.measure();
Serial.print(qt4);
Serial.print(",");
qt5 = qt_5.measure();
Serial.print(qt5);
Serial.println();
qt6 = qt_6.measure();
Serial.print(qt6);
Serial.println();
qt7 = qt_7.measure();
Serial.print(qt7);
Serial.println();
if (qt1 >= qt_Threshold1) {
sound(1);
}
if (qt2 >= qt_Threshold2) {
sound(2);
}
if (qt3 >= qt_Threshold3) {
sound(3);
}
if (qt4 >= qt_Threshold4) {
sound(4);
}
if (qt5 >= qt_Threshold5) {
sound(5);
}
if (qt6 >= qt_Threshold6) {
sound(6);
}
if (qt7 >= qt_Threshold7) {
sound(7);
}
}
void sound(uint8_t note_index)
{
for (int i = 0; i < 50; i++)
{
digitalWrite(SPEAKER, HIGH);
delayMicroseconds(BassTab[note_index]);
digitalWrite(SPEAKER, LOW);
delayMicroseconds(BassTab[note_index]);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment