For this project we were tasked with the assignment of creating a simple input and output device:
Come up with a simple application using digital and/or analog input and output to a microcontroller. Make a device that allows a person to control light, sound, or movement using the components you’ve learned about (e.g. LEDs, speakers, servomotors)
Ahmed was really inspired by close encounters of the third kind and the communication between two parties with sound and light:
Close incounters final scene… with a weird crossover at the end…
The key thing that we were detracting from the nearby experience thing is this idea of Dialog. How would you have a real conversation with a machine? In pondering it, John and I were reminded of a key idea of information theory- the information content of a system. Envision a page. In the event that it is completely loaded up with arbitrary letters it is totally indiscernible. Same as well in the event that it is totally loaded up with one letter. All things considered, all things considered the example is truly straightforward, yet it is easy to the point that it has almost no significance and is unbelievably exhausting. The secret to language is a fine harmony among shock and redundancy. A discourse is likewise a fascinating focal thought. In an exchange there is a call and a reaction. One gathering expresses, the different tunes in and afterward reacts while the primary party tunes in. In a discourse there is a sure measure of redundancy that is important so as to cause it to appear as though you are being heard. That is clear about the nearby experiences model: the people produce a yield, the outsiders emulate it and afterward develop it. I can’t help thinking about how I can start to implement that.
//int pbnoties[ 3 ][ 3 ] = {{NOTE_C4, NOTE_C5,NOTE_C6},{NOTE_E4, NOTE_E5,NOTE_E6},{NOTE_G4, NOTE_G5,NOTE_G6}};
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int buttonPin3 = 4 ;
const int buttonPin4 = 5 ;
const int ledPin = 10;
int leds[3]={13,12,11};
bool buttonState1 = false;
bool buttonState2 = false;
bool buttonState3 = false;
bool buttonLocked = false;
bool buttonJustPressed = false;
bool awake = false;
bool listening = true;
//arrays
const int maximum = 40;
int buttonsPressed[maximum];
int pausesBeforePlaying[maximum];
int durationOfPresses[maximum];
int noteCount = 0;
int playbackIndex = 0;
//data
int pressStarted = 0;
int prevPressEndedAt = 0;
int pressLength = 0;
int gapLength = 0;
int currentPressedButton = 0;
//playback
int playState = 0;
int currentPause = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
//buttons
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(14, OUTPUT);
pinMode(15, OUTPUT);
pinMode(16, OUTPUT);
Serial.begin(9600);
//speaker
pinMode(8,OUTPUT);
}
void loop() {
//modeswitch
if(awake){
if(millis()-prevPressEndedAt>=2000&&listening){
listening = false;
playbackIndex = -1; //noteCount;;
playState = 2;
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
}
}
/////record and playback
if(listening){
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
///recording
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
digitalWrite(ledPin, LOW);
if(buttonState1||buttonState2||buttonState3){
awake = true;
if (digitalRead(buttonPin1)==HIGH){
buttonPressed(1);
delay(10);
}
if (digitalRead(buttonPin2)==HIGH){
buttonPressed(2);
delay(10);
}
if (digitalRead(buttonPin3)==HIGH){
buttonPressed(3);
delay(10);
}
}else{
if(buttonJustPressed){
buttonReleased();
}
}
}else{
///playback
playback();
if(digitalRead(buttonPin1)||digitalRead(buttonPin2)||digitalRead(buttonPin3)){
noTone(8);
listening = true;
noteCount = 0;
prevPressEndedAt = millis();
//
memset(buttonsPressed, 0, sizeof(buttonsPressed));
memset(pausesBeforePlaying, 0, sizeof(pausesBeforePlaying));
memset(durationOfPresses, 0, sizeof(durationOfPresses));
};
}
}
void buttonPressed(int button){
if(!buttonLocked){
currentPressedButton = button;
pressStarted = millis();
tone(8,noties[button-1][0]);
// Serial.println(noties[button][0]);
buttonLocked = true;
buttonJustPressed = true;
gapLength = pressStarted – prevPressEndedAt;
Serial.println(pressStarted);
}
}
void buttonReleased(){
noTone(8);
buttonLocked = false;
pressLength = millis()-pressStarted;
if(pressLength&&gapLength){
Serial.print(noteCount);
Serial.println(” —————————–“);
Serial.print(“button-“);
Serial.println(currentPressedButton);
Serial.print(“length-“);
Serial.println(pressLength);
Serial.print(“gap- “);
Serial.println(gapLength);
//writing to arrays
buttonsPressed[noteCount]= currentPressedButton;
pausesBeforePlaying[noteCount]= gapLength;
durationOfPresses[noteCount]=pressLength;
noteCount++;
if(noteCount==maximum){
noteCount = 0;
}
}
buttonJustPressed = false;
prevPressEndedAt = millis();
}
void playback(){
digitalWrite(ledPin, HIGH);
switch (playState) {
case 0://init
currentPause = millis();
playState = 1;
break;
case 1://waiting
if(millis()-currentPause>=pausesBeforePlaying[playbackIndex]){
playState = 2;
currentPause = millis();
}
break;
case 2: //emit
if(buttonsPressed[playbackIndex]){
Serial.print(playbackIndex);
Serial.println(” ||||||||||||||||||||||”);
Serial.print(“button-“);
Serial.println(buttonsPressed[playbackIndex]);
// Serial.print(noties[playbackIndex-1][1]);
Serial.print(“length-“);
Serial.println(durationOfPresses[playbackIndex]);
Serial.print(“gap- “);
Serial.println(pausesBeforePlaying[playbackIndex]);
tone(8, noties[(buttonsPressed[playbackIndex])-1][random(3)]); /// 0 this is getting weird
digitalWrite(leds[(buttonsPressed[playbackIndex])-1], HIGH);
playState = 3;
}else{playState = 4;}
break;
case 3: //hold
if(millis()-currentPause>= durationOfPresses[playbackIndex]){
digitalWrite(leds[(buttonsPressed[playbackIndex])-1], LOW);
playState= 4;
}
break;
case 4: //release
noTone(8);
// digitalWrite(leds[(buttonsPressed[playbackIndex])-1], LOW);
playbackIndex++;
if(playbackIndex==maximum){
delay(700);
awake = false;
listening = true;
playbackIndex = 0;
} ///it would be nice to make this cut the playback off
playState = 0;
break;
}
}
May 24, 2021