BoxHead


2

I used a flex sensor to change tones coming out of the piezo. I used an additional potentiometer in the circuit to gain access to more variety/manipulation of tones.

1

CODE:

#include “pitches.h”
int speaker = 12;
int sensor = A0;
int sensorValue = 0;

void setup(){
Serial.begin(9600); //baud rate
pinMode(sensor, INPUT);
pinMode(speaker, OUTPUT);
}

void loop(){

sensorValue = analogRead(sensor);
Serial.println(sensorValue);
sensorValue = map(sensorValue, 1, 35, 31, 4978);
Serial.println(sensorValue);

tone(speaker, sensorValue);
delay(1000/8);
noTone(speaker);
}

Leave a Reply

Your email address will not be published.