// 2 digit sayıcı
// 12 ve 13 display seçici
// 2,3,4,5,6,7,8 sıra ile abcdefg dir.
#include <Servo.h>
Servo myservo;
int pos = 0;
const int speakerPin = A0; // connect speaker to pin 9
char noteNames[] = {'C','D','E','F','G','a','b'};
unsigned int frequencies[] = {262,294,330,349,392,440,494};
const byte noteCount = sizeof(noteNames); // number of notes (7 here)
//notes, a space represents a rest
char score[] = "CCGGaaGFFEEDDC";
const byte scoreLen = sizeof(score); // the number of notes in the score
// G-F-E-D-C-B-A
int digit[10] = {0b0111111, 0b0000110, 0b1011011, 0b1001111,
0b1100110, 0b1101101, 0b1111101, 0b0000111, 0b11111111,
0b1101111};
int digit1, digit2;
int pil = A3;
int j = 0;
int ilkV=0;
int say=0;
int angle=0;
int button= 0;
void setup()
{
Serial.begin(9600);
for (int i = 2; i < 9; i++)
{
pinMode(i, OUTPUT);
}
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
pinMode(11, OUTPUT); //nokta
pinMode(9, INPUT); // BUTON
myservo.attach(10);
// show amaçlı display bir sefer dans ediyor
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
for (int i = 2; i < 8; i++)
{
digitalWrite(i, HIGH);
delay(100);
digitalWrite(i, LOW);
}
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
for (int i = 2; i < 8; i++)
{
digitalWrite(i, HIGH);
delay(100);
digitalWrite(i, LOW);
}
}
void loop() {
// for (int j = 0; j <= 99; j++)
// {
int pilv = analogRead(pil);
int j=(pilv/102.3)*5.0;
// Serial.println(ilkV);
button = digitalRead(9);
if (ilkV==0||ilkV==j){
ilkV=j;
say++;
if(say>=4&&j<=13&&button==HIGH)
pilServo();
else if(say>=2&&j>13&&button==HIGH)
{
for (int i = 0; i < scoreLen; i++)
{
int duration = 333; // each note lasts for a third of a second
playNote(score, duration); // play the note
say=0;
ilkV=0;
}
}
}else{
say=0;
ilkV=0;
}
digit2 = j / 10;
digit1 = j % 10;
for ( int k = 0; k < 20; k++)
{
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
digitalWrite(11, HIGH);// nokta
dis(digit2);
delay(10);
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
dis(digit1);
delay(10);
}
// }
}
void pilServo(){
for(pos = 148; pos>=70; pos-=1) // 70 DEĞERİ SERVO ALT SINIRI. 150 DEN 70 DERECEYE İNER
{
myservo.write(pos); //
delay(10); //
}
delay(1000);
for(pos = 70; pos <= 148; pos += 1) // 150 DEĞERİ SERVO ÜST SINIRI. 70 TEN 150 DERECEYE ÇIKAR
{ //
myservo.write(pos); //
delay(20); //
}
delay(1000);
// for (int i = 0; i < scoreLen; i++)
// {
// int duration = 333; // each note lasts for a third of a second
// playNote(score, duration); // play the note
// }
ilkV==0;
say=0;
}
void dis(int num)
{
for (int i = 2; i < 9; i++)
{
digitalWrite(i, bitRead(digit[num], i - 2));
}
}
void playNote(char note, int duration)
{
// play the tone corresponding to the note name
for (int i = 0; i < noteCount; i++)
{
// try and find a match for the noteName to get the index to the note
if (noteNames == note) // find a matching note name in the array
tone(speakerPin, frequencies, duration); // play the note
}
// if there is no match then the note is a rest, so just do the delay
delay(duration);
}