2013-12-01

Arduino ultimo codigo.


El código fuente completo final de esta semana.


/*

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

3 semaforo VERDE
4 AMARILLO
5 ROJO

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
#include

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

void rojo()
{
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
}

void amarillo()
{
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
}


void verde()
{
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}



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);

pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);

digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);

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()) < 3) { if (inputString[0] == 'R') rojo(); if (inputString[0] == 'A') amarillo(); if (inputString[0] == 'V') verde(); digitalWrite (LATCH, LOW); SPI.transfer (B10000000); // ultimo digito SPI.transfer (B11000000); // cero digitalWrite (LATCH, HIGH); } else { 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; k0 and second()<20) // rojo(); // if (second()>19 and second()<40) // amarillo(); // if (second()>39 and second()<60) // verde(); } void converso () { // DADO UN NUMERO lo pasa a binario para el display // 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

No hay comentarios:

Por el mundo