Output devices
This week I decided to start working on the code and board I will need for my final project.I started to make a schema ,for my input I will use a motion sensor to detect wen the ball will stop moving.
for my output I will need a speaker,several leds and a small motor.
I started with an Arduino code that will make a wavy sound as I play with the sensor
Mill the board and solder the components on it.
I used sokets for the piezo sensor and motor and pin for the speaker .
I conected the FTDI and the AVR to the board and borend the botloder. then check the pin nombers.
And burn the code on the Attiny 44.
// - LEAD MELODY int cycVec[] = { 1136,1136 ,1073, 1073, 1276, 1276, 1073, 1136, 1136, 1136, 1073, 1073, 1701, 1805, 1136, 1805, 1515, 1515, 1433, 1433, 1701, 1701, 1433,1515, 1136, 1136, 1073, 1073, 1276, 1276, 1073, 1136,1276,1136}; int noteDurations [] = { 440 ,220 ,466 , 466 , 392, 392, 233, 1320, 440 ,220, 466, 466, 294, 277, 220, 554, 330, 165, 349, 349, 294, 294, 174, 990 , 440, 220, 466, 466, 392, 392, 233, 220, 196, 440, 220, 220}; int noteLength = 34; int delayInBetween = 3; int BPS = 10; // this constant won't change: const int piezoPin = 2; // the pin that the piezo is attached to const int motorPin = 3; // the pin that the motor is attached to long motorTime = 0; int piezoState = 0; int ledOne= 10; int ledTwo= 9; int ledThree= 4; void setup() { pinMode(piezoPin, INPUT); // initialize the button pin as a input: pinMode(motorPin, OUTPUT); pinMode(ledOne, OUTPUT); pinMode(ledTwo, OUTPUT); pinMode(ledThree, OUTPUT); // initialize serial communication: int speaker =7; pinMode(speaker, OUTPUT); for (int m=0;m { noteDurations[m] = (noteDurations[m])/BPS; //pauseDuration[k] = pauseDuration[k]*1000; } } void loop() { // piezoState = digitalRead(piezoPin); // read the pushbutton i // Serial.println(piezoState); int speaker =7; int temp; int cycNum; int cyc; if ( motorTime == 0 ) { if ( detectMovement() ) { digitalWrite(motorPin, HIGH); delay(5000); digitalWrite(motorPin, LOW); delay(400); digitalWrite(ledOne, HIGH); delay (30); digitalWrite(ledTwo, HIGH); delay(300); digitalWrite(ledThree, HIGH); delay (300); digitalWrite(speaker, LOW); digitalWrite(ledOne, LOW); digitalWrite(ledTwo, LOW); digitalWrite(ledThree,LOW); for (int thisNote = 0; thisNote { for (int i=0;i { digitalWrite(speaker, HIGH); digitalWrite(ledOne, HIGH); digitalWrite(ledTwo, HIGH); digitalWrite(ledThree, HIGH); delayMicroseconds(cycVec[thisNote]); digitalWrite(speaker, LOW); digitalWrite(ledOne, LOW); digitalWrite(ledTwo, LOW); digitalWrite(ledThree,LOW); delayMicroseconds(cycVec[thisNote]); } } } } else { if ( (millis()-motorTime)>10000 ) { motorTime = 0; digitalWrite(motorPin, LOW); // startPlayback(sample, sizeof(sample)); } } }You ken dawonlode the Arduino files hare.
Check evrithing workes on your board and make modefection in the code if nesasery.
Success.