KamilCaliskan / arduino

0 stars 0 forks source link

R2R_voice.ino #5

Open KamilCaliskan opened 1 year ago

KamilCaliskan commented 1 year ago

include <avr/pgmspace.h>

int ledPins[8] = {0,1, 2, 3, 4, 5, 6, 7}; const byte sound[] PROGMEM = {128,

128, 128, 128, 127, 128, 127, 128, 127, 128, 127, 128, 128}; int pin, i;

void setup() { for(pin=0; pin<=7; pin++) pinMode(ledPins[pin], OUTPUT); }

void loop() {

for (i=0; i<sizeof(sound); i++) { PORTD=sound[i];

delay(0.0625);

} delay(2000); }

KamilCaliskan commented 1 year ago

byte i=0,sayi=0; bool dac[8]={0,0,0,0,0,0,0,0}; void setup() { for (i=24;i<39;i++){ pinMode(i,OUTPUT); pinMode(12,OUTPUT); digitalWrite(i,0);}
}

void loop() { sayi=80+80sin(0.001float(millis())); //Ör. 211 analogWrite(12,sayi); dac[7]=sayi/128; //bit7=floor(211/128)=1; sayi-=128dac[7]; //sayi=211-1281=83; dac[6]=sayi/64; //bit6=floor(83/64)=1; sayi-=64dac[6]; //sayi=83-641=19; dac[5]=sayi/32; //bit5=floor(19/32)=0; sayi-=32dac[5]; //sayi=19-320=19; dac[4]=sayi/16; //bit4=floor(19/16)=1; sayi-=16dac[4]; //sayi=19-161=3; dac[3]=sayi/8; //bit3=floor(3/8)=0; sayi-=8dac[3]; //sayi=3-80=3; dac[2]=sayi/4; //bit2=floor(3/4)=0; sayi-=4dac[2]; //sayi=3-40=3; dac[1]=sayi/2; //bit1=floor(3/2)=1; dac[0]=sayi-2dac[1]; //sayi=3-21=1; for (i=0;i<8;i++){ digitalWrite(38-2*i,dac[i]); } delay(10); }