Klimberdaja

Klimberdaja is audio visual music generator and player. Like a simple automated piano or something like that.

Klimberdaja
Klimberdaja

I wanted to learn how Shift Registers work and then I did it.

klimberdaja_pordid_4gy0UUrgzk

klimberdaja_schem_QP2X1nkhzc

Arduino Code:

//
const int volumePin = 7;
//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
//Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;

/*
note frequency
c 262 Hz
d 294 Hz
e 330 Hz
f 349 Hz
g 392 Hz
a 440 Hz
b 494 Hz
C 523 Hz
*/
int notes[] = {262, 294, 330, 349, 392, 440, 494, 523};

int sensorValue;//potsentsiomeeter

void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
sensorValue = analogRead(A0);
// random number from 48 to 57
int bitToSet = random(0, 8);

Serial.println(bitToSet);
registerWrite(bitToSet, HIGH);

tone(volumePin, notes[bitToSet]);

if (sensorValue < 40){
sensorValue = 40;
}
delay(sensorValue);

}
// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
byte bitsToSend = 0;

// turn off the output so the pins don’t light up
// while you’re shifting bits:
digitalWrite(latchPin, LOW);

// turn on the next highest bit in bitsToSend:
bitWrite(bitsToSend, whichPin, whichState);

// shift the bits out:
shiftOut(dataPin, clockPin, MSBFIRST, bitsToSend);

// turn on the output so the LEDs can light up:
digitalWrite(latchPin, HIGH);

}

First published in: https://www.hackster.io/taunoerik/klimberdaja-49a003

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.