Hallo zusammen!
Schlage mich seit Tagen mit dem PROGMEN herum, vielleicht
kennt jemand das Problem und weiß Rat.
Beschreibung des Problems:
Ich habe viele Daten mit denen ich nicht den RAM vollstopfen möchte und so kam ich auf die Idee, PROGMEM
zu benutzen.
Also habe ich die Arrays so wie in der Anleitung zu lesen
ist arrangiert und der Compiler übersetzt auch alles prima.
Der Kern des Problems ist, das die Offset Variable irgendwie anfangs einen falschen Wert hat obwohl der Wert
jeweils neu errechnet wird.
Die Daten die ich über midi schicke kommen in meinem Monitor Programm an, nur die ersten ca. 200-300 Bytes sind
nicht die aus meinem Array.
Wenn ich den Offsetwert selber ausrechne und direkt als Startwert reinschreibe, kommen die Daten korrekt an.
Ich poste hier mal den Code, den ich auf das nötigste zusammen gestrichen habe. Aber Sorry ist ev. doch noch zu lang.
Es ist die Funktion
int RomPrgTo_Midi_(UINT num_);// sounds block nach midi out ...
#ifndef MidiD19z_
#define MidiD19z_
#include <avr/pgmspace.h>
//#include <TimerOne.h>
#include <Arduino.h>
#include <EEPROM.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h> // Vorher hinzugefügte LiquidCrystal_I2C Bibliothek einbinden
LiquidCrystal_I2C lcd(0x27,40,2); // 2 zeiliges I2C-LCD mit 40 Zeichen pro Zeile ...
#include "defauls.h"
#include "proto_.h"
#include "atachment_.h"
//#include "progs_.h"
//#include "timers_.h"
//#include "funktion_.h"
int RomPrgTo_Midi_(UINT num_);// sounds block nach midi out ...
void setup()
{
lcd.init(); //Im Setup wird der LCD gestartet
lcd.backlight(); //Hintergrundbeleuchtung einschalten
lcd.leftToRight();
lcd.clear();
lcd.home();
pinMode(pAD0_,OUTPUT);
pinMode(pAD1_,OUTPUT);
pinMode(pAD2_,OUTPUT);
pinMode(pAD3_,OUTPUT);
pinMode(13,OUTPUT);
pinMode(pD10_,OUTPUT);
pinMode(pD11_,OUTPUT);
pinMode(pD12_,OUTPUT);
pinMode(pD02_,INPUT);
pinMode(pD03_,INPUT);
pinMode(pD08_,INPUT);
pinMode(MidiOut_M1_,OUTPUT);
pinMode(MidiOut_M2_,OUTPUT);
Serial.begin(31250); // midi sequenz ....
digitalWrite(13,HIGH); // midi_in an ...
digitalWrite(MidiOut_M1_,HIGH); // midiout 1+2 an ...
digitalWrite(MidiOut_M2_,HIGH);
// **************** init xv2020 *************************************
xv2020_channel_on_(0); // schaltet beim xv2020 die midi,
// empfangs chans ein ...
delay(500);
xv2020_play_mode_(0); // stellt den play mode ein ....
delay(500);
zTimer_1 = 0;
iBytes_ = 0;
attachInterrupt(0,INT_0_,LOW); // poti top und tasten ...
attachInterrupt(1,INT_1_,RISING); // nur poti links / rechts ...
}
byte bOUT_ = 2 // programm nummer ....
RomPrgTo_Midi_((UINT)bOUT_); // sounds block nach midi out ...
void loop()
{
//goto nono_;
//goto nix_7;
//**************** timer ***********************************************
if (millis() > zTIMER_) // abfrager begrenzer ...
{
zTIMER_ = millis()+100;
if (zTIMER_ > zUSER_TIME_)
fFlipFlop_ = ON;
zPop_=1;
} // millis ...
//*************** was testen ... *****************************************
//******************* druck abfrage ... **********************************
if (fFlipFlop_ == ON) // 10 x sek. ...
{
potiDruck_(zPNUM_);
// if (millis() > zTimer_2) // abfrager begrenzer ...
zPNUM_++;
if (zPNUM_ > 7) zPNUM_=0;
fFlipFlop_=OFF;
}
//return;
//**************** prints .... *****************************
if (fPrints_ == ON) // gesetzt kommt print ...
{
detachInterrupt(0);
detachInterrupt(1);
// zTimer_2 = millis()+500;
lcd.setCursor(dspl_v_,line_1_);// das erste Zeichen in der ersten Zeile.
lcd.print(fTaste_);
lcd.print("T ");
lcd.print(zT_); // druck poti/taste ...
lcd.print("zT_ ");
lcd.print(zL_); // poti drehen links/rechts ...
lcd.print("zL_ ");
lcd.print(zR_); // poti drehen links/rechts ...
lcd.print("zR_ ");
fLinks_=0;
fRechts_=0;
// fTaste_=0; // schalter ...
fPrints_=0;
zINP_=0;
while (digitalRead(pD02_) == LOW) {}; // top losgelassen ?
zUSER_TIME_ = zTIMER_+tPOTI_;
end_:
attachInterrupt(0,INT_0_,LOW); // nur poti links / rechts ...
attachInterrupt(1,INT_1_,RISING); // poti top und tasten ...
}
}// loop ...
int RomPrgTo_Midi_(UINT num_) // sounds block nach midi out ...
{
midi_dout_(198); // direkt byte out ...
midi_dout_((byte)num_); // direkt byte out ...
midi_dout_(198); // direkt byte out ...
midi_dout_((byte)num_); // direkt byte out ...
delay(10);
digitalWrite(MidiOut_M1_,HIGH); // an XV-2020 midiout 1 an ...
digitalWrite(MidiOut_M2_,LOW);
offset_ = num_*77;
iZ_=0;
while (iZ_++ < 77)
{
outByte_ = pgm_read_ptr(&(SoundDaten_XV2020[offset_++]));
midi_dout_(outByte_); // direkt byte out ...
}
digitalWrite(MidiOut_M1_,LOW); // an JV-1010 midiout 2 an ...
digitalWrite(MidiOut_M2_,HIGH);
offset_ = num_*77;
iZ_=0;
while (iZ_++ < 77)
{
outByte_ = pgm_read_ptr(&(SoundDaten_JV1010[offset_++]));
midi_dout_(outByte_); // direkt byte out ...
}
digitalWrite(MidiOut_M1_,HIGH); // an XV20 midiout 1 an ...
digitalWrite(MidiOut_M2_,HIGH); // an JV-1010 midiout 2 an ...
return 0;
}
#ifndef defauls_
#define defauls_
#define UINT unsigned int
#define ULONG unsigned long
// ************** programm flag's definieren **********************
ULONG zTimer_1,zTimer_2;
ULONG zTIMER_;
ULONG zTIMEOUT_;
ULONG zTIMER_POTI_;
ULONG zUSER_TIME_;
UINT offset_= 0; // offset der sound daten ...
// **************** daten ***************************
byte iZ_;
int zTop_ = 0;
int zPop_ = 0;
int fPrints_ = 0; // gesetzt kommt print ...
int fLinks_ = 0; // poti links ...
int fRechts_ = 0; // poti rechts ...
int fTaste_ = 0; // taste, poti Top gedrückt ...
int tPOTI_ = 1000; // msec poti freigabe time ...
byte TIMEOUT = 100; // poti nicht l nger abfragen ...
byte TIMEOUT_POTI_ = 10; // in poti abfrage ...
byte zPNUM_=0; // potinummern z hler ...
byte PNUM_=0; // ausgew hlte poti/taste ...
//*************** programm flag's definieren **********************
bool ON = 1;
bool OFF = 0;
//******************* blocks hier hin *************************************
//
// jeweils der erste Block einer Programm-Nummer ist f r XV-2020
// und somit ist der jeweils folgende Block f r JV-1010
// in beiden blocks wird aus Gr nden der einfacheren handbarkeit
// das PrgChange - Event f r den Virtualizer gespeichert ..
//
// ********************* START-DATENBLOCK ******************************
// ******************** block 1-8 f r XV-2020 ***************************
// ******************** block 1-8 f r JV-1010 ***************************
//SndBlock_: ; 72 Byte ...
// offset 77 * ProgNummer ...
const byte SoundDaten_XV2020[] PROGMEM = {
//const byte BLK10001[] = {
177, 7, 87, // volume ...
178, 7, 75,
179, 7, 60,
180, 7, 29,
181, 7, 36,
177, 0, 87, // Bank -
177, 32, 65, // selct ..
193, 6, // prg change chan 2, bass sound ..
178, 0, 87, // Bank -
178, 32, 64, // selct ..
194, 89, // prg change chan 3, chord 1 sound ..
179, 0, 87, // Bank -
179, 32, 64, // selct ..
195, 83, // prg change chan 4, chord 2 sound ..
180, 0, 87, // Bank -
180, 32, 64, // selct ..
196, 50, // prg change chan 5, chord 3 sound ..
181, 0, 87, // Bank -
181, 32, 65, // selct ..
197, 18, // prg change chan 6, chord 4 sound ..
177, 10, 118, // Control cange chan 2, bass pan ...
178, 10, 53, // Control cange chan 3, chord pan ...
179, 10, 91, // Control cange chan 4, chord pan ...
180, 10, 87, // Control cange chan 5, chord pan ...
181, 10, 45, // Control cange chan 6, chord pan ...
188, 0, 1, // Control cange chan 13, bank
204, 0, // Control cange chan 13 f r virtualizer ...
255, 255,//}; // block abschluss ...
//const byte BLK10002[] = {
177, 7, 87,
178, 7, 75,
179, 7, 60,
180, 7, 29,
181, 7, 36,
177, 0, 87,
177, 32, 65,
193, 6,
178, 0, 87,
178, 32, 64,
194, 89,
179, 0, 87,
179, 32, 64,
195, 83,
180, 0, 87,
180, 32, 64,
196, 50,
181, 0, 87,
181, 32, 65,
197, 18,
177, 10, 118,
178, 10, 53,
179, 10, 91,
180, 10, 87,
181, 10, 45,
187, 0, 1, // ; chan 12 platzhalter ..
203, 0, //; chan 12 ohne verwendung ...
255, 255,//};
//const byte BLK10003[] = {
177, 7, 87,
178, 7, 75,
179, 7, 60,
180, 7, 29,
181, 7, 36,
177, 0, 87,
177, 32, 65,
193, 6,
178, 0, 87,
178, 32, 64,
194, 89,
179, 0, 87,
179, 32, 64,
195, 83,
180, 0, 87,
180, 32, 64,
196, 50,
181, 0, 87,
181, 32, 65,
197, 18,
177, 10, 118,
178, 10, 53,
179, 10, 91,
180, 10, 87,
181, 10, 45,
188, 0, 1,
204, 0, // ; chan 13 f r virtualizer ...
255, 255,//};
//const byte BLK10004[] = {
177, 7, 87,
178, 7, 75,
179, 7, 60,
180, 7, 29,
181, 7, 36,
177, 0, 87,
177, 32, 65,
193, 6,
178, 0, 87,
178, 32, 64,
194, 89,
179, 0, 87,
179, 32, 64,
195, 83,
180, 0, 87,
180, 32, 64,
196, 50,
181, 0, 87,
181, 32, 65,
197, 18,
177, 10, 118,
178, 10, 53,
179, 10, 91,
180, 10, 87,
181, 10, 45,
187, 0, 1, //; chan 12 platzhalter ..
203, 0, // ; chan 12 ohne verwendung ...
255, 255,//};
//const byte BLK10005[] = {
177, 7, 87,
178, 7, 75,
179, 7, 60,
180, 7, 29,
181, 7, 36,
177, 0, 87,
177, 32, 65,
193, 6,
178, 0, 87,
178, 32, 64,
194, 89,
179, 0, 87,
179, 32, 64,
195, 83,
180, 0, 87,
180, 32, 64,
196, 50,
181, 0, 87,
181, 32, 65,
197, 18,
177, 10, 118,
178, 10, 53,
179, 10, 91,
180, 10, 87,
181, 10, 45,
188, 0, 1,
204, 0, // ; chan 13 f r virtualizer ...
255, 255,//};
//const byte BLK10006[] = {
177, 7, 87,
178, 7, 75,
179, 7, 60,
180, 7, 29,
181, 7, 36,
177, 0, 87,
177, 32, 65,
193, 6,
178, 0, 87,
178, 32, 64,
194, 89,
179, 0, 87,
179, 32, 64,
195, 83,
180, 0, 87,
180, 32, 64,
196, 50,
181, 0, 87,
181, 32, 65,
197, 18,
177, 10, 118,
178, 10, 53,
179, 10, 91,
180, 10, 87,
181, 10, 45,
187, 0, 1, //; chan 12 platzhalter ..
203, 0, // ; chan 12 ohne verwendung ...
255, 255,//};
//const byte BLK10007[] = {
177, 7, 87,
178, 7, 75,
179, 7, 60,
180, 7, 29,
181, 7, 36,
177, 0, 87,
177, 32, 65,
193, 6,
178, 0, 87,
178, 32, 64,
194, 89,
179, 0, 87,
179, 32, 64,
195, 83,
180, 0, 87,
180, 32, 64,
196, 50,
181, 0, 87,
181, 32, 65,
197, 18,
177, 10, 118,
178, 10, 53,
179, 10, 91,
180, 10, 87,
181, 10, 45,
188, 0, 1,
204, 0, // ; chan 13 f r virtualizer ...
255, 255,//};
//const byte BLK10008[] = {
177, 7, 82,
178, 7, 100,
179, 7, 71,
180, 7, 35,
181, 7, 84,
177, 0, 87,
177, 32, 65,
193, 79,
178, 0, 87,
178, 32, 64,
194, 36,
179, 0, 87,
179, 32, 0,
195, 63,
180, 0, 87,
180, 32, 66,
196, 78,
181, 0, 87,
181, 32, 67,
197, 39,
177, 10, 118,
178, 10, 53,
179, 10, 91,
180, 10, 87,
181, 10, 45,
187, 0, 1, // ; chan 12 platzhalter ..
203, 0, // ; chan 12 ohne verwendung ...
255, 255};
const byte SoundDaten_JV1010[] PROGMEM = {
//const byte BLK10001[] = {
// ; chan 12 platzhalter ..
// gleicher aufbau nur andere byte werte ....
203, 0, // ; chan 12 ohne verwendung ...
255, 255};
#endif