Sorry for bothering, but I have a question where I haven't found an "elegant" solution yet because of lack of expertise.
Problem: I need to continuosly output a 72bit pattern with variable speed.
Therefore the intention is to connect a potentiometer to one of the analog input for adjusting the program speed
There are two different 72 BitPatterns which are selected by a different pin.
Now my two questions: the max frequency by which the bits should be sent to the output is about 8,5 kHz and adjustable by the potentiometer value.
How can I realize this in a smart manner?
Question two: At the moment I store the 72bits as bytes, which is a huge waste of space. I had in mind storing them as bits in µP EEprom, but do I assume correctly I can only write/read the Bits bytewise in eeprom?
Thanks for reading and your support!
BR
Ralf
//
// 72 Bit Bitfolge ausgeben ohne Delay
//
// Rechnen:
// RPM max = 7000 U/min = 117 U/s
// 117 * 72 Bit = 8424 Hz -> 0,1187 ms Periodendauer
//
// #include <EEPROM.h>
byte OUTPin=13; // Signal Output Pin
byte MPIPin=12; // Signal select pin
int analogPin = A3; // Analog Input
int analogVal = 0; // Analog Value
// SPI Pattern 18-1 *2 = 72 Bit
int mySPI[72] =
{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0
};
// MPI Pattern
// 13 Zähne
// 1 Lücke
// 3 Zähne
// 1 Lücke
// 14 Zähne
// 1 Lücke
// 2 Zähne
// 1 Lücke
int myMPI[72] =
{ 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,0
};
void setup()
{
pinMode(OUTPin, Output};
pinMode(SELECTPin, Input_pullup);
}
void loop()
{
//
analogVal = analogRead(analogPin); // read the input pin
//
//
if (MPIPin = HIGH)
{ for (int i =0 ; i<= 71; i++)
if (myMPI(i) == 1) { {
digitalWrite(OUTPin, HIGH);
}
else
{
digitalWrite(OUTPin, LOW);
}
}
else
{ for (int i =0 ; i<= 71; i++)
if (mySPI(i) == 1)
{
digitalWrite(OUTPin, HIGH);
}
else
{
digitalWrite(OUTPin, LOW);
}
}
}