summaryrefslogtreecommitdiff
path: root/Blinkme_spi/Blinkme_spi.ino
diff options
context:
space:
mode:
authorJörg Biemann <joerg@Jorgs-MacBook-Pro.local>2012-07-28 01:09:21 +0200
committerJörg Biemann <joerg@Jorgs-MacBook-Pro.local>2012-07-28 01:09:21 +0200
commitf7721742d23d8a9ba1df7837fba5931f99aa63ce (patch)
tree2950c719b74a9450228c5a68bfe0b187a3dab798 /Blinkme_spi/Blinkme_spi.ino
parent4590d60345fb5a3891c3894a1dec098f835395f1 (diff)
Nun mit Bitmuster zum Blinken
Signed-off-by: Jörg Biemann <joerg@Jorgs-MacBook-Pro.local>
Diffstat (limited to 'Blinkme_spi/Blinkme_spi.ino')
-rw-r--r--Blinkme_spi/Blinkme_spi.ino138
1 files changed, 138 insertions, 0 deletions
diff --git a/Blinkme_spi/Blinkme_spi.ino b/Blinkme_spi/Blinkme_spi.ino
new file mode 100644
index 0000000..f0afa6a
--- /dev/null
+++ b/Blinkme_spi/Blinkme_spi.ino
@@ -0,0 +1,138 @@
+#include <SPI.h>
+
+
+// Definition des Datenpaketes
+// Länge: 1 Byte
+// Adressierung der LED: 5 Bit
+// Maske: 0xF8
+// Helligkeitswert: 3 Bit
+// Maske: 0x7
+// Dadurch 31 LEDs adressierbar mit 7 Helligkeitswerten
+//
+// * CS - to digital pin 10 (SS pin)
+// * SDI - to digital pin 11 (MOSI pin)
+// * SDI - to digital pin 12 (MISO pin)
+// * CLK - to digital pin 13 (SCK pin)
+
+
+
+// Vorbereitungen um als Slave Daten zu empfangen
+byte recieve_buff [255];
+volatile byte pos;
+volatile boolean process_it;
+
+// PINS fuer SPI
+const int slaveSelectPin = 10;
+const int miso = 12;
+const int mosi = 11;
+
+const int ledPin = 2;
+
+//Array fuer Helligkeitswerte Led, 2te Dimension gibt Position im Muster wieder
+byte brightnessMatrix[31][2];
+
+//Array fuer Led Pin Adressen
+byte ledAdresse[31];
+
+//Fuer For Schleifen im Loop
+int brightLimit = 100;
+int posLed = 3;
+
+
+// Matrix fuer Helligkeitsmuster
+int bitMusterHelligkeit[][100] =
+{
+ {
+ 0,0,0,0,0,0,0,0,2 }
+ ,
+ {
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2 }
+ ,
+ {
+ 0,0,0,0,0,0,1,0,0,0,0,0,0,1,2 }
+ ,
+ {
+ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,2 }
+ ,
+ {
+ 0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,2 }
+ ,
+ {0,1,1,1,0,1,1,1,2 },
+ {0,1,1,1,0,1,1,1,2 },
+ {
+ 1,1,1,1,1,1,1,1,2 }
+};
+
+
+
+void setup() {
+ Serial.begin (115200); // debugging
+
+ pinMode(slaveSelectPin, INPUT);
+ pinMode(miso, OUTPUT);
+
+ // SPI als Slave aktivieren
+ SPCR |= _BV(SPE);
+
+ // interrupt vorbereitung
+ pos =0; //recieve Buffer leer
+ process_it = false;
+ SPI.attachInterrupt();
+
+
+ //Leds initialisieren
+ for(int i=0;i<31;i++){
+ brightnessMatrix[i][1]=0;
+ }
+
+ // initialize the digital pin as an output.
+ pinMode(ledPin, OUTPUT);
+
+ digitalWrite (ledPin, HIGH);
+ delay(1000);
+ digitalWrite (ledPin, LOW);
+
+
+}
+
+//Interrupt fuer SPI
+ISR (SPI_STC_vect)
+{
+ byte buffer = SPDR;
+ //Schreibt im Array an die Adresse im Datenpaket den Wert
+ brightnessMatrix[2][0]=SPDR&0x07;
+
+// brightnessMatrix[SPDR&0xf8][0]=SPDR&0x07;
+ digitalWrite (ledPin, HIGH);
+
+ digitalWrite (ledPin, LOW);
+
+}
+
+
+void loop()
+{
+ Serial.println(brightnessMatrix[2][0]);
+ for(int i=0;i<31;i++){
+
+ if(brightnessMatrix[i][0]){
+ digitalWrite(/*ledAdresse[i]*/2,HIGH);
+ brightnessMatrix[i][1]==brightnessMatrix[i][1]++;
+ }
+ else if(brightnessMatrix[i][0]==0){
+
+ digitalWrite(/*ledAdresse[i]*/2,LOW);
+ }
+ else {
+ brightnessMatrix[i][1]=0;
+ }
+
+ }
+
+
+}
+
+
+
+
+