Ciao Jackson!Grazie per il reply..attualmente ho davvero pochissimo tempo causa università..comunque qualche progresso arriva.
Ho fatto un paio di protoboard:
-interfaccia per l'input con CD4021 (ho trovato questo)
-interfaccia per l'output con i '595 e dei led per vedere lo stato
ho occupato in tutto 6 pin I/O più ovviamente i pin di alimentazione come da tutorial di arduino.
Quindi ora riesco a gestire ingressi e uscite (notare che per ora ho solo 8 ingressi ovvero pulsanti, che amplierò a 16 e in uscita il secondo 595 replica il primo per questo motivo).
Ora ho in programma di fare una scheda con i relè pilotati dai 74hc595 (e uln2803) e poi basta "solo" gestire via software l'input dei pulsanti a seconda del tipo di switching che voglio..e l'idea è che non servano solo per commutare il canale corrispondente ma anche muoversi nelle funzioni interne del software.
Questo è tutto quello che sono riuscito faticosamente a fare
L'unica incertezza la riscontro nella velocità del sistema: quando voglio che a pulsante premuto si attivi l'uscita corrispondente, ad esempio premo il pushbutton 1 e attivo la prima uscita del '595, noto una leggera latenza. Credo dipenda dal programma e dal fatto che non uso la trasmissione seriale nativa del microcontrollore(spero di non aver detto c****e).
..ecco perchè sono bloccato.
Prometto di fare un post piu chiaro appena ho più tempo!!
per riferimento allego lo sketch
Codice: Seleziona tutto
//define where your pins are
int clockPin = 7;
int latchPin = 8;
int dataPin = 9;
//Pin connected to 74HC595
int OclockPin = 10;
int OlatchPin = 11;
int OdataPin = 12;
byte buttonVar = 0;
byte buttonVarold = 1;
byte switchVar = 0;
void setup() {
//start serial
// Serial.begin(9600);
//define pin modes
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, INPUT);
pinMode(OlatchPin, OUTPUT);
pinMode(OclockPin, OUTPUT);
pinMode(OdataPin, OUTPUT);
}
void loop() {
//Pulse the latch pin:
//set it to 1 to collect parallel data
digitalWrite(latchPin,1);
//set it to 1 to collect parallel data, wait
delayMicroseconds(20);
//set it to 0 to transmit data serially
digitalWrite(latchPin,0);
//while the shift register is in serial mode
//collect each shift register into a byte
//the register attached to the chip comes in first
switchVar = shiftIn(dataPin, clockPin);
//campionamento del valore corrispondente alla pressione del pulsante:
if (switchVar != 0){
buttonVar = switchVar;
}
if (buttonVar != buttonVarold){
digitalWrite(OlatchPin, LOW);
// shift out the bits:
shiftOut(OdataPin, OclockPin, MSBFIRST, buttonVar);
shiftOut(OdataPin, OclockPin, MSBFIRST, buttonVar);
//take the latch pin high so the LEDs will light up:
digitalWrite(OlatchPin, HIGH);
buttonVarold = buttonVar;
}
}
//------------------------------------------------end main loop
////// ----------------------------------------shiftIn function
///// just needs the location of the data pin and the clock pin
///// it returns a byte with each bit in the byte corresponding
///// to a pin on the shift register. leftBit 7 = Pin 7 / Bit 0= Pin 0
byte shiftIn(int myDataPin, int myClockPin) {
int i;
int temp = 0;
int pinState;
byte myDataIn = 0;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, INPUT);
//we will be holding the clock pin high 8 times (0,..,7) at the
//end of each time through the for loop
//at the begining of each loop when we set the clock low, it will
//be doing the necessary low to high drop to cause the shift
//register's DataPin to change state based on the value
//of the next bit in its serial information flow.
//The register transmits the information about the pins from pin 7 to pin 0
//so that is why our function counts down
for (i=7; i>=0; i--)
{
digitalWrite(myClockPin, 0);
delayMicroseconds(0.2);
temp = digitalRead(myDataPin);
if (temp) {
pinState = 1;
//set the bit to 0 no matter what
myDataIn = myDataIn | (1 << i);
}
else {
//turn it off -- only necessary for debuging
//print statement since myDataIn starts as 0
pinState = 0;
}
//Debuging print statements
//Serial.print(pinState);
//Serial.print(" ");
//Serial.println (dataIn, BIN);
digitalWrite(myClockPin, 1);
}
//debuging print statements whitespace
//Serial.println();
//Serial.println(myDataIn, BIN);
return myDataIn;
}
edit: dimenticavo..tutti i led vari saranno gestiti da un max 7219..appena mi arriverà..anche se ormai temo lo abbiano perso per strada le poste...