Codigo Completo con todo.


El código con todo dentro.
Display de 7 segmentos
Board con 16 Relays
Display 8 x 8 Segmentos (8x7)
Switch en PIN 10 para input.

/*

Mix demo ALL-INCLUSIVE
dac FREECODE 2013-11

30-46 connected to 16 relay board

14-21 connected to 7 segment display

10 connected to switch

ICSP conencted to 8 x 8 segment display
1 negro a 6 RCK
2 azul a NADA
3 blanco a SCK
4 gris a DID
6 violet a GND

XXXXXXXX
1 PUNTO
2 cen
3 arr izq
4 aba izq
5 aba
6 aba der
7 arr der
8 arr

*/

#include

const byte LATCH = 51;
String inputString = "";
boolean stringComplete = false;
String conv = "";

void setup() {

digitalWrite(SS, HIGH);
SPI.begin ();
SPI.setClockDivider(SPI_CLOCK_DIV2);

digitalWrite (LATCH, LOW);
SPI.transfer (B10000000); // INICIO ultimo digito
SPI.transfer (B11000000); // esta en cero
digitalWrite (LATCH, HIGH);


Serial.begin(9600);
inputString.reserve(20);

pinMode(10, INPUT);

int i = 0;
for (i == 0; i<16; i++)
{
pinMode(30+i, OUTPUT);
digitalWrite(30+i, HIGH);
}

int j = 0;
for (j == 0; j<8; j++)
{
pinMode(14+j, OUTPUT);
digitalWrite(14+j, HIGH);
}
}



void loop() {
if (stringComplete) {

Serial.println( digitalRead (10) );
if ( (inputString.length()-1) <= 10)
{
converso();
digitalWrite (LATCH, LOW);
SPI.transfer (B10000000); // ULTIMO DIGITO
SPI.transfer (B11111001); // 1
digitalWrite (LATCH, HIGH);

int k = 0;
for (k == 0; k {
if ( inputString[k] == '1')
{
// Serial.println( '1' );
digitalWrite(14+k, LOW);
}
else
{
// Serial.println( '0' );
digitalWrite(14+k, HIGH);
}
}
}
else
{
digitalWrite (LATCH, LOW);
SPI.transfer (B10000000); // ultimo digito
SPI.transfer (B10100100); // 2
digitalWrite (LATCH, HIGH);

int l = 0;
for (l == 0; l {
if ( inputString[l] == '1')
{
// Serial.println( '1' );
digitalWrite(30+l, LOW);
}
else
{
// Serial.println( '0' );
digitalWrite(30+l, HIGH);
}
}
};

// Serial.println(inputString);
inputString = "";
stringComplete = false;
}
}


void converso () {
// if (inputString =='11111111')
conv = "";
// 'B10000000';

// if (inputString =='00000001')
// conv = 'B00000001';

// if (inputString =='00000010')
// conv = 'B00000011';
}

void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
if (inChar == '\n') {
stringComplete = true;
}
}
}
// end of code

Comentarios

Entradas populares