const int inputPin = 9; // Číslo digitálního vstupního pinu
const int rawDataSize byteArraySize = 10; // Velikost byteového pole
byte byteArray[rawData]; // Byteové pole pro ukládání hodnoty
void setup() {
Serial.begin(9600); // inicializace sériové komunikace na 9600 baudů
pinMode(inputPin, INPUT_PULLUP); // Nastavení pinu 9 jako vstupní pin s pull-up rezistorem
}
void loop() {
int sensorValue = digitalRead(inputPin); // // Čtení hodnoty z digitálního pinu
saveByteToByteArray(sensorValue); // Uložení hodnoty do byteového pole
// dalsi akce
}
void saveByteToByteArray(byte newByte) {
// Posunutí dat v byteovém poli doprava (zahodí se první byte, poslední bude nový)
for (int i = 0; i < rawSataSize - 1; i++)
{
byteArray[i] = byteArray[i + 1];
}
byteArray[byteArraySize - 1] = newByte; // // Uložení nového bytu na konec pole
}
declare an array like this
byte theArray[4] = 0; //declares an array with 4 positions and sets them all to zero
declare a variable to use as an index to the array
byte arrayIndex = 0; //index to the array
Now, when you want to save a value do this
theArray[arrayIndex] = theValue;
arrayIndex++; //increment the array index to the next position
if (arrayIndex == 4)
{
//the array has 4 entries numbered from 0 to 3 and is now full
//code here to test the array entries
}
Set the array entries back to zero with a for loop
for (arrayIndex = 0; arrayIndex < 4; arrayIndex++)
{
theArray[arrayIndex] = 0;
}