Go Down

Topic: help with 74hc165 and pushbuttons (Read 120 times) previous topic - next topic

mpampellona

Apr 19, 2017, 10:36 am Last Edit: Apr 19, 2017, 04:49 pm by mpampellona
Good day.

My project is to make a piano using pushbuttons.

I tested out my 74hc165 ics. Tried daisy chaining it. And it works perfectly. I used iamzxlee's code to test out my setup. Link below.

My concern now is how can i tell which button was pushed. e.g. if button 5 is pressed, the arduino will read that the button 5 is HIGH.
From there, if button 5 is HIGH, it will play a certain note. If it is LOW, it will not play anything.

I cant decipher which code should perfectly fit to this task. Pls help. This is for my project with a deadline two weeks from now. Thankyou in advance!!

https://iamzxlee.wordpress.com/2014/05/13/74hc165-8-bit-parallel-inserial-out-shift-register/

septillion

WHY DO YOU NEED TO SCREAMMMMMM? (please edit that ;) )

And no link... Also, shouldn't be a link, you should inline it WITH code- tags :)
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

mpampellona

#2
Apr 19, 2017, 03:49 pm Last Edit: Apr 19, 2017, 04:03 pm by mpampellona
Oops sorry about that ha ha!

Code: [Select]

//shift register experiment
//coded by zxlee
//iamzxlee.wordpress.com
 
#include <LiquidCrystal.h>
 
LiquidCrystal lcd(6,7,8,9,10,11);
 
#define enable 2
#define load 3
#define clock 4
#define data 5
 
void setup()
{
lcd.begin(16,2);
pinMode(enable,OUTPUT);
pinMode(load,OUTPUT);
pinMode(clock,OUTPUT);
pinMode(data,INPUT);
digitalWrite(load,HIGH);
digitalWrite(enable,HIGH);
lcd.print("Input = ");
Serial.begin(9600);
}
 
void loop()
{
digitalWrite(load,LOW);
delayMicroseconds(5);
digitalWrite(load,HIGH);
delayMicroseconds(5);
 
digitalWrite(clock,HIGH);
digitalWrite(enable,LOW);
byte incoming=shiftIn(data,clock,MSBFIRST);
digitalWrite(enable,HIGH);
 
for(int i=7;i>=0;i--)
{
if(bitRead(incoming,i)==1)
{
lcd.setCursor((15-i),0);
lcd.print("1");
}
else
{
lcd.setCursor((15-i),0);
lcd.print("0");
}
}
 
}

Grumpy_Mike

#3
Apr 20, 2017, 07:50 am Last Edit: Apr 20, 2017, 07:51 am by Grumpy_Mike
After the lcd.print("1" ) line generate the tone, the frequency should be determined by the value of the loop index i.

mpampellona

Thankyou sir for replying.

Solved my problem with switch and case codes.

I studied how the incoming byte data enters the arduino and put case statements on it.

Go Up