summaryrefslogtreecommitdiff
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
parent4590d60345fb5a3891c3894a1dec098f835395f1 (diff)
Nun mit Bitmuster zum Blinken
Signed-off-by: Jörg Biemann <joerg@Jorgs-MacBook-Pro.local>
-rw-r--r--Blinkme_spi.ino77
-rw-r--r--Blinkme_spi/Blinkme_spi.ino138
2 files changed, 138 insertions, 77 deletions
diff --git a/Blinkme_spi.ino b/Blinkme_spi.ino
deleted file mode 100644
index 3943fe3..0000000
--- a/Blinkme_spi.ino
+++ /dev/null
@@ -1,77 +0,0 @@
-#include <SPI.h>
-
-// * 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
-char recieve_buff [100];
-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;
-
-
-void setup() {
-
- 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();
-
- // initialize the digital pin as an output.
- pinMode(ledPin, OUTPUT);
-
- digitalWrite (ledPin, HIGH);
- delay(1000);
- digitalWrite (ledPin, LOW);
-}
-
-//PINS/Bitmask fuer LEDs
-int LED0 = 0x01;
-int LED1 = 0x02;
-int LED2 = 0x04;
-int LED3 = 0x08;
-
-int PWM_BASE = 15;
-
-
-ISR (SPI_STC_vect)
-{
- byte c = SPDR;
- if (pos < sizeof recieve_buff)
- {
- recieve_buff[pos++] = c;
- process_it = true;
- }
-}
-
-
-void loop()
-{
-
- //Verarbeitung der empfangenen Nachricht
- if (process_it == true)
- {
- if (recieve_buff[pos] == 0x31)
- digitalWrite (ledPin, HIGH);
- else if (recieve_buff[pos] == 0x30)
- digitalWrite (ledPin, LOW);
-
- process_it == false;
- pos = 0;
- }
-}
-
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;
+ }
+
+ }
+
+
+}
+
+
+
+
+