INFO: Dieses Forum nutzt Cookies...
Cookies sind für den Betrieb des Forums unverzichtbar. Mit der Nutzung des Forums erklärst Du dich damit einverstanden, dass wir Cookies verwenden.

Es wird in jedem Fall ein Cookie gesetzt um diesen Hinweis nicht mehr zu erhalten. Desweiteren setzen wir Google Adsense und Google Analytics ein.

Antwort schreiben 
 
Themabewertung:
  • 0 Bewertungen - 0 im Durchschnitt
  • 1
  • 2
  • 3
  • 4
  • 5
3 Stück LED 8x8 Matrix via Array ansteuern
09.10.2017, 18:58
Beitrag #9
RE: 3 Stück LED 8x8 Matrix via Array ansteuern
(09.10.2017 11:12)Tommy56 schrieb:  Probier mal test[0] anstelle von test.

Gruß Tommy
Das war es Big Grin.

Hab das Pferd jetzt mal von hinten aufgezäumt und hab aus dem vorgabe-Sketch alles gelöscht was nichts mit Arrays und Bitmaps auf Matrix projezieren zutun hat und es ist folgendes raus gekommen:
Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"

Adafruit_BicolorMatrix matrix[4] = Adafruit_BicolorMatrix();
static const uint8_t PROGMEM matrixAddr[] = { 0x70, 0x71, 0x72, 0x73 };
static const uint8_t PROGMEM
  test[][32] = {                
  { B11000111, B00011110, B11000011, B11111111,
    B11000110, B01111110, B11000011, B11111111,
    B11001100, B11100000, B11000011, B11000000,
    B11011000, B11000000, B11000011, B11111000,
    B11111000, B11000000, B11000011, B11111000,
    B11111000, B11100000, B11000011, B11000000,
    B11001100, B01111110, B01111110, B11000000,
    B11000111, B00011110, B00111100, B11000000 },
  };

void setup() {
  Serial.begin(9600);
  Serial.println("8x8 LED Matrix Test");
  
   matrix[0].begin(0x70);
   for(uint8_t i=0; i<4; i++) {
   matrix[i].begin(0x70 + i);
  }
}


void loop() {
  
  drawIt(test[0]);
}

void drawIt(const uint8_t *test){
  
for(uint8_t i=0;i<4;i++){
   matrix[i].setRotation(1);
   matrix[i].clear();
   matrix[i].drawBitmap(i * -8, 0, test, 32, 8, LED_GREEN);
   matrix[i].writeDisplay();
   delay(500);
  }
}

Hier haben die für deine Lösung eben eine Funktion gemacht.
Danke Big Grin
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
09.10.2017, 19:00
Beitrag #10
RE: 3 Stück LED 8x8 Matrix via Array ansteuern
Gut, dass es funktioniert. Es ist besser, sich von vorn herein an sprechende Variablennamen zu gewöhnen. Alle Test zu nennen ist keine gute Idee.

Gruß Tommy

"Wer den schnellen Erfolg sucht, sollte nicht programmieren, sondern Holz hacken." (Quelle unbekannt)
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
30.10.2017, 19:33
Beitrag #11
RE: 3 Stück LED 8x8 Matrix via Array ansteuern
Bin grad echt blind und weiß nicht was gerade an meinem Sketch falsch ist.
Das Problem ist dass der Taster2 dauer gedrückt wird.
Folgendes kann ich ausschließen:
1. Hardware ist nicht defekt. Alles bestens verkabelt und funktioniert auch mit einem anderen sketch.
2. Eingebettete Bibliotheken/Quellcodes sind nicht dran schuld

hier der Sketch:
Code:
#include <WaveHC.h>
#include <WaveUtil.h>
#include <Wire.h>
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
//--------------------------------------------------------------------------------------AUGEN
Adafruit_BicolorMatrix matrix[4] = Adafruit_BicolorMatrix();

static const uint8_t PROGMEM // Bitmaps are stored in program memory
  AugenR[][32] = {    // Eye animation frames
  { B01000000, B00000000, B00000000, B00000010,
    B01100011, B11000000, B00000011, B11000110,
    B01111111, B11110000, B00001111, B11111110,
    B01111111, B11111000, B00011111, B11111110,
    B00111111, B11111100, B00111111, B11111100,
    B00001111, B11111110, B01111111, B11110000,
    B00000011, B11000110, B01100011, B11000000,
    B00000000, B00000010, B01000000, B00000000 },
  { B01000000, B00000000, B00000000, B00000010,
    B01100011, B11000000, B00000011, B11000110,
    B01111111, B11100000, B00000111, B11111110,
    B00111111, B11110000, B00001111, B11111100,
    B00011111, B11111000, B00011111, B11111000,
    B00000111, B11111100, B00111111, B11100000,
    B00000001, B11000110, B01100011, B10000000,
    B00000000, B00000010, B01000000, B00000000 },
  { B01000000, B00000000, B00000000, B00000010,
    B01100011, B10000000, B00000001, B11000110,
    B00111111, B11000000, B00000011, B11111100,
    B00011111, B11100000, B00000111, B11111000,
    B00001111, B11110000, B00001111, B11110000,
    B00000001, B11111000, B00011111, B10000000,
    B00000001, B11000100, B00100011, B10000000,
    B00000000, B00000010, B01000000, B00000000 },
  { B00000000, B00000000, B00000000, B00000000,
    B00100000, B00000000, B00000000, B00000100,
    B00011111, B00000000, B00000000, B11111000,
    B00000111, B11000000, B00000011, B11100000,
    B00000000, B00000000, B00000000, B00000000,
    B00000000, B00000000, B00000000, B00000000,
    B00000000, B00000000, B00000000, B10000000,
    B00000000, B00000010, B01000000, B00000000 },
  { B00000000, B00000000, B00000000, B00000000,
    B00000000, B00000000, B00000000, B00000000,
    B00000000, B00000000, B00000000, B00000000,
    B00000000, B00000000, B00000000, B00000000,
    B00000000, B00000000, B00000000, B00000000,
    B00000000, B00000000, B00000000, B00000000,
    B00000000, B00000000, B00000000, B00000000,
    B00000000, B00000000, B01000000, B00000000 }};
    static const uint8_t PROGMEM // Bitmaps are stored in program memory
  AugenG[][32] =    // Eye animation frames
  { B00000000, B00000000, B00000000, B00000000,
    B00000011, B11000000, B00000011, B11000000,
    B00000111, B11100000, B00000111, B11100000,
    B00001110, B01110000, B00001110, B01110000,
    B00011100, B00111000, B00011100, B00111000,
    B00011100, B00111000, B00011100, B00111000,
    B00111000, B00011100, B00111000, B00011100,
    B00000000, B00000000, B00000000, B00000000 };

uint8_t
  blinkIndex[] = { 1, 2, 3, 4, 3, 2, 1 }, // Blink bitmap sequence
  blinkCountdown = 100, // Countdown to next blink (in frames)
  gazeCountdown  =  75, // Countdown to next eye movement
  gazeFrames     =  50, // Duration of eye movement (smaller = faster)
  mouthPos       =   0, // Current image number for mouth
  mouthCountdown =  10; // Countdown to next mouth change
int8_t
  eyeX = -1, eyeY = 3,   // Current eye position
  newX = 3, newY = 3,   // Next eye position
  dX   = 0, dY   = 0;   // Distance from prior to new position


//________________________________________________________________________________​______AUGEN

SdReader  card;  // This object holds the information for the card
FatVolume vol;   // This holds the information for the partition on the card
FatReader root;  // This holds the information for the volumes root directory
FatReader file;  // This object represent the WAV file for a pi digit or period
WaveHC    wave;  // This is the only wave (audio) object, -- we only play one at a time
#define error(msg) error_P(PSTR(msg))  // Macro allows error messages in flash memory

#define ADC_CHANNEL 0 // Microphone on Analog pin 0

// Wave shield DAC: digital pins 2, 3, 4, 5
#define DAC_CS_PORT    PORTD
#define DAC_CS         PORTD2
#define DAC_CLK_PORT   PORTD
#define DAC_CLK        PORTD3
#define DAC_DI_PORT    PORTD
#define DAC_DI         PORTD4
#define DAC_LATCH_PORT PORTD
#define DAC_LATCH      PORTD5

uint16_t in = 0, out = 0, xf = 0, nSamples; // Audio sample counters
uint8_t  adc_save;                          // Default ADC mode

extern uint8_t
  buffer1[PLAYBUFFLEN],                   // Audio sample LSB
  buffer2[PLAYBUFFLEN];                   // Audio sample MSB
#define XFADE     16                      // Number of samples for cross-fade
#define MAX_SAMPLES (PLAYBUFFLEN - XFADE) // Remaining available audio samples


uint8_t       oldsum = 0;
unsigned long newsum = 0L;

  int taster2=11 , taster3=9 , taster4=8, taster5=7 , taster6=6 , taster7=12 , taster8=13;
  int tasterstatus2=0 , tasterstatus3=0 , tasterstatus4=0, tasterstatus5=0 , tasterstatus6=0 , tasterstatus7=0, tasterstatus8=0;
  int xWert=7;
  int pitch=0;


//////////////////////////////////// SETUP

void setup() {

//----------------------------------------------------------------------------------------AUGEN
  randomSeed(analogRead(A0));


  for(uint8_t i=0; i<4; i++) {
    matrix[i].begin(0x70 + i);
  }
//________________________________________________________________________________​________AUGEN
  uint8_t i;

  Serial.begin(9600);
  
  pinMode(taster2, INPUT);
  pinMode(taster3, INPUT);
  pinMode(taster4, INPUT);
  pinMode(taster5, INPUT);
  pinMode(taster6, INPUT);
  pinMode(taster7, INPUT);
  pinMode(taster8, INPUT);



  pinMode(2, OUTPUT);    // Chip select
  pinMode(3, OUTPUT);    // Serial clock
  pinMode(4, OUTPUT);    // Serial data
  pinMode(5, OUTPUT);    // Latch
  digitalWrite(2, HIGH); // Set chip select high

  // Init SD library, show root directory.  Note that errors are displayed
  // but NOT regarded as fatal -- the program will continue with voice FX!
  if(!card.init())             SerialPrint_P("Card init. failed!");
  else if(!vol.init(card))     SerialPrint_P("No partition!");
  else if(!root.openRoot(vol)) SerialPrint_P("Couldn't open dir");
  else {
    PgmPrintln("Files found:");
    root.ls();
  }
  TIMSK0 = 0;

  // Set up Analog-to-Digital converter:
  analogReference(EXTERNAL); // 3.3V to AREF
  adc_save = ADCSRA;         // Save ADC setting for restore later

  startPitchShift();     // and start the pitch-shift mode by default.
}

//////////////////////////////////// LOOP

void loop() {
  tasterstatus2=digitalRead(taster2);
  tasterstatus3=digitalRead(taster3);
  tasterstatus4=digitalRead(taster4);
  tasterstatus5=digitalRead(taster5);
  tasterstatus6=digitalRead(taster6);
  tasterstatus7=digitalRead(taster7);
  tasterstatus8=digitalRead(taster8);

  


  if(tasterstatus2 == HIGH){
    xWert = 2;
    Serial.println(xWert);
    stopPitchShift();
    pitch = 10;
    startPitchShift();
  }
  else if (tasterstatus3 == HIGH){
    xWert = 3;
    Serial.println(xWert);
    stopPitchShift();
    pitch = 512;
    startPitchShift();
  }
  else if (tasterstatus4 == HIGH){
    xWert = 4;
    Serial.println(xWert);
    stopPitchShift();
    pitch = 1023;
    startPitchShift();
    
  }
    else if (tasterstatus5 == HIGH){
    xWert = 5;
    Serial.println(xWert);
    stopPitchShift();
    pitch = 1023;
    startPitchShift();
    
  }
    else if (tasterstatus6 == HIGH){
    xWert = 6;
    Serial.println(xWert);
    stopPitchShift();
    pitch = 1023;
    startPitchShift();
    
  }
    else if (tasterstatus7 == HIGH){
    xWert = 7;
    Serial.println(xWert);
    stopPitchShift();
    pitch = 1023;
    startPitchShift();
    
  }
    else if (tasterstatus8 == HIGH){
    xWert = 8;
    Serial.println(xWert);
    stopPitchShift();
    pitch = 1023;
    startPitchShift();
    
  }
  else {
  }

//-------------------------------------------------------------------------------------------AUGEN

Serial.println(xWert);

  if (xWert == 8){
    for(uint8_t i=0;i<4;i++){
    matrix[i].clear();
    matrix[i].setRotation(3);
    }
    matrix[0].drawCircle(7,4, 2, LED_YELLOW);
    matrix[1].drawCircle(-1,4, 2, LED_YELLOW);
    matrix[2].drawCircle(8,4, 2, LED_YELLOW);
    matrix[3].drawCircle(0,4, 2, LED_YELLOW);
  }
  else if (xWert == 7){
    for(uint8_t i=0;i<4;i++){
  matrix[i].setRotation(3);
  matrix[i].clear();
  matrix[i].drawBitmap(i * -8, 0, AugenG[0], 32, 8, LED_GREEN);
  }
  }
  else{
      for(uint8_t i=0;i<4;i++){
  matrix[i].setRotation(3);
  matrix[i].clear();
  matrix[i].drawBitmap(i * -8, 0, AugenR[ (blinkCountdown < sizeof(blinkIndex)) ? blinkIndex[blinkCountdown] :  0  ], 32, 8, LED_RED);
  if(--blinkCountdown == 0) blinkCountdown = random(5, 180);
  delay(5);
  
  matrix[0].fillRect(7, 2, 2, 4, LED_OFF);
  matrix[1].fillRect(-1, 2, 2, 4, LED_OFF);
  matrix[2].fillRect(7, 2, 2, 4, LED_OFF);
  matrix[3].fillRect(-1, 2, 2, 4, LED_OFF);
  }
  }

  for(uint8_t i=0; i<4; i++) matrix[i].writeDisplay();

  delay(20); // ~50 FPS
//________________________________________________________________________________​___________AUGEN

}

void startPitchShift() {


  Serial.print("Pitch: ");
  Serial.println(pitch);

  nSamples = 128;


  memset(buffer1, 0, nSamples + XFADE); // Clear sample buffers
  memset(buffer2, 2, nSamples + XFADE); // (set all samples to 512)


  TCCR2A = _BV(WGM21) | _BV(WGM20); // Mode 7 (fast PWM), OC2 disconnected
  TCCR2B = _BV(WGM22) | _BV(CS21) | _BV(CS20);  // 32:1 prescale
  OCR2A  = map(pitch, 0, 1023,
    F_CPU / 32 / (9615 / 2),  // Lowest pitch  = -1 octave
    F_CPU / 32 / (9615 * 2)); // Highest pitch = +1 octave

  // Start up ADC in free-run mode for audio sampling:
  DIDR0 |= _BV(ADC0D);  // Disable digital input buffer on ADC0
  ADMUX  = ADC_CHANNEL; // Channel sel, right-adj, AREF to 3.3V regulator
  ADCSRB = 0;           // Free-run mode
  ADCSRA = _BV(ADEN) |  // Enable ADC
    _BV(ADSC)  |        // Start conversions
    _BV(ADATE) |        // Auto-trigger enable
    _BV(ADIE)  |        // Interrupt enable
    _BV(ADPS2) |        // 128:1 prescale...
    _BV(ADPS1) |        //  ...yields 125 KHz ADC clock...
    _BV(ADPS0);         //  ...13 cycles/conversion = ~9615 Hz

  TIMSK2 |= _BV(TOIE2); // Enable Timer2 overflow interrupt
  sei();                // Enable interrupts
}

void stopPitchShift() {
  ADCSRA = adc_save; // Disable ADC interrupt and allow normal use
  TIMSK2 = 0;        // Disable Timer2 Interrupt
}

ISR(ADC_vect, ISR_BLOCK) { // ADC conversion complete

  // Save old sample from 'in' position to xfade buffer:
  buffer1[nSamples + xf] = buffer1[in];
  buffer2[nSamples + xf] = buffer2[in];
  if(++xf >= XFADE) xf = 0;

  // Store new value in sample buffers:
  buffer1[in] = ADCL; // MUST read ADCL first!
  buffer2[in] = ADCH;

  newsum += abs((((int)buffer2[in] << 8) | buffer1[in]) - 512);

  if(++in >= nSamples) {
    in     = 0;
    oldsum = (uint8_t)((newsum / nSamples) >> 1); // 0-255
    newsum = 0L;
  }
}

ISR(TIMER2_OVF_vect) { // Playback interrupt
  uint16_t s;
  uint8_t  w, inv, hi, lo, bit;
  int      o2, i2, pos;

  // Cross fade around circular buffer 'seam'.
  if((o2 = (int)out) == (i2 = (int)in)) {
    // Sample positions coincide.  Use cross-fade buffer data directly.
    pos = nSamples + xf;
    hi = (buffer2[pos] << 2) | (buffer1[pos] >> 6); // Expand 10-bit data
    lo = (buffer1[pos] << 2) |  buffer2[pos];       // to 12 bits
  } if((o2 < i2) && (o2 > (i2 - XFADE))) {
    // Output sample is close to end of input samples.  Cross-fade to
    // avoid click.  The shift operations here assume that XFADE is 16;
    // will need adjustment if that changes.
    w   = in - out;  // Weight of sample (1-n)
    inv = XFADE - w; // Weight of xfade
    pos = nSamples + ((inv + xf) % XFADE);
    s   = ((buffer2[out] << 8) | buffer1[out]) * w +
          ((buffer2[pos] << 8) | buffer1[pos]) * inv;
    hi = s >> 10; // Shift 14 bit result
    lo = s >> 2;  // down to 12 bits
  } else if (o2 > (i2 + nSamples - XFADE)) {
    // More cross-fade condition
    w   = in + nSamples - out;
    inv = XFADE - w;
    pos = nSamples + ((inv + xf) % XFADE);
    s   = ((buffer2[out] << 8) | buffer1[out]) * w +
          ((buffer2[pos] << 8) | buffer1[pos]) * inv;
    hi = s >> 10; // Shift 14 bit result
    lo = s >> 2;  // down to 12 bits
  } else {
    // Input and output counters don't coincide -- just use sample directly.
    hi = (buffer2[out] << 2) | (buffer1[out] >> 6); // Expand 10-bit data
    lo = (buffer1[out] << 2) |  buffer2[out];       // to 12 bits
  }

  DAC_CS_PORT &= ~_BV(DAC_CS);
  DAC_DI_PORT  &= ~_BV(DAC_DI); // 0 = Select DAC A, unbuffered
  DAC_CLK_PORT |=  _BV(DAC_CLK); DAC_CLK_PORT &= ~_BV(DAC_CLK);
  DAC_CLK_PORT |=  _BV(DAC_CLK); DAC_CLK_PORT &= ~_BV(DAC_CLK);
  DAC_DI_PORT  |=  _BV(DAC_DI); // 1X gain, enable = 1
  DAC_CLK_PORT |=  _BV(DAC_CLK); DAC_CLK_PORT &= ~_BV(DAC_CLK);
  DAC_CLK_PORT |=  _BV(DAC_CLK); DAC_CLK_PORT &= ~_BV(DAC_CLK);
  for(bit=0x08; bit; bit>>=1) { // Clock out first 4 bits of data
    if(hi & bit) DAC_DI_PORT |=  _BV(DAC_DI);
    else         DAC_DI_PORT &= ~_BV(DAC_DI);
    DAC_CLK_PORT |=  _BV(DAC_CLK); DAC_CLK_PORT &= ~_BV(DAC_CLK);
  }
  for(bit=0x80; bit; bit>>=1) { // Clock out last 8 bits of data
    if(lo & bit) DAC_DI_PORT |=  _BV(DAC_DI);
    else         DAC_DI_PORT &= ~_BV(DAC_DI);
    DAC_CLK_PORT |=  _BV(DAC_CLK); DAC_CLK_PORT &= ~_BV(DAC_CLK);
  }
  DAC_CS_PORT    |=  _BV(DAC_CS);    // Unselect DAC

  if(++out >= nSamples) out = 0;
}
Alle Beiträge dieses Benutzers finden
Diese Nachricht in einer Antwort zitieren
Antwort schreiben 


Möglicherweise verwandte Themen...
Thema: Verfasser Antworten: Ansichten: Letzter Beitrag
Sad Arduino Matrix Led Laufschrift fehlkauf_1234 4 321 26.10.2018 17:13
Letzter Beitrag: Chopp
  array aus Methode/Funktion sepp01 3 230 14.10.2018 19:16
Letzter Beitrag: Tommy56
  [gelöst]String, char .... ich begreife es einfach nicht - char Array <> mit SDexist christian@schiltkamp.info 10 934 31.08.2018 23:05
Letzter Beitrag: Tommy56
  900 WS2812 ansteuern b_mertke 6 622 31.08.2018 12:45
Letzter Beitrag: Hilgi
  Array mit 433MHz-Modul versenden Matthias_Arduino 14 922 22.08.2018 15:20
Letzter Beitrag: hotsystems
  Menu mit char*Array TKRoth 7 808 01.05.2018 21:02
Letzter Beitrag: MicroBahner
  Led Matrix dani1994 3 587 03.03.2018 12:44
Letzter Beitrag: hotsystems
  SSR (Solid State Relais) mit PID-Regler ansteuern pernschi 10 1.668 05.01.2018 15:13
Letzter Beitrag: hotsystems
Question Relais in Reihenfolge ansteuern. Jonas Lindenblatt 32 3.484 27.12.2017 12:40
Letzter Beitrag: MiReu
  String nach Byte Array in ASCII-Codierung nexus1212 7 1.567 05.11.2017 14:36
Letzter Beitrag: Tommy56

Gehe zu:


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste