Update 'Old_Code/Arduino_i2c.ino'
parent
161b73dfa0
commit
e69720ff46
|
@ -1,50 +1,50 @@
|
||||||
#include <Wire.h> // I2C-Headerdatei
|
#include <Wire.h> // I2C-Headerdatei
|
||||||
|
|
||||||
const int adcPin = A0; // ADC-Pin
|
const int adcPin = A0; // ADC-Pin
|
||||||
//const int toggleDelay = 0.1; // Verzögerung zwischen dem Umschalten der Bits, in Mikrosekunden
|
//const int toggleDelay = 0.1; // Verzögerung zwischen dem Umschalten der Bits, in Mikrosekunden
|
||||||
const int bufferSize = 8 * sizeof(uint32_t);
|
const int bufferSize = 8 * sizeof(uint32_t);
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Wire.begin(8); // I2C-Verbindung initialisieren
|
Wire.begin(8); // I2C-Verbindung initialisieren
|
||||||
analogReadResolution(12);
|
analogReadResolution(12);
|
||||||
//Serial.begin(9600);
|
//Serial.begin(9600);
|
||||||
|
|
||||||
//Wire.onReceive(receiveData);
|
//Wire.onReceive(receiveData);
|
||||||
//Wire.onRequest(sendData);
|
//Wire.onRequest(sendData);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*void sendData() {
|
/*void sendData() {
|
||||||
Wire.write(0xFF);
|
Wire.write(0xFF);
|
||||||
Serial.write(0xFF);
|
Serial.write(0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
void receiveData(int count) {
|
void receiveData(int count) {
|
||||||
Serial.write('r');
|
Serial.write('r');
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
uint32_t buffer[8] = {0};
|
uint32_t buffer[8] = {0};
|
||||||
uint8_t bitCount = 0;
|
uint8_t bitCount = 0;
|
||||||
|
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
uint32_t randomValue = 0;
|
uint32_t randomValue = 0;
|
||||||
|
|
||||||
while (bitCount < 32) {
|
while (bitCount < 32) {
|
||||||
uint16_t adcValue = analogRead(adcPin);
|
uint16_t adcValue = analogRead(adcPin);
|
||||||
uint32_t newBit = adcValue & 0x01;
|
uint32_t newBit = adcValue & 0x01;
|
||||||
randomValue = (randomValue << 1) | newBit;
|
randomValue = (randomValue << 1) | newBit;
|
||||||
bitCount++;
|
bitCount++;
|
||||||
//delay(toggleDelay);
|
//delay(toggleDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer[i] = randomValue;
|
buffer[i] = randomValue;
|
||||||
bitCount = 0;
|
bitCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Wire.beginTransmission(8); // I2C-Übertragung an Geräteadresse 8 starten
|
Wire.beginTransmission(8); // I2C-Übertragung an Geräteadresse 8 starten
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
Wire.write((byte*)&buffer[i], sizeof(buffer[i])); // Daten über I2C-Bus senden
|
Wire.write((byte*)&buffer[i], sizeof(buffer[i])); // Daten über I2C-Bus senden
|
||||||
}
|
}
|
||||||
Wire.endTransmission(); // I2C-Übertragung beenden */
|
Wire.endTransmission(); // I2C-Übertragung beenden */
|
||||||
}
|
}
|
Loading…
Reference in New Issue