So, I have a very basic project where I cycle through 8 IR individual transmitters. After setting the individual transmitter high, I cycle through all 8 IR receivers and print their values, RX_CYCLES many times. I need a huge amount, quality data from these loops to train a neural net, so
I want to optimize my code to where I can analogRead
each receiver the fastest, but keep the maximum resolution possible.
I'm having trouble understanding Teensy's documentation and provided libraries and finding any relevant resources that are clear enough for me to weave through the jargon.
My questions are:
- What would be or how do I go about calculating the optimization or balance of the fastest baudrate I can match with the Teensy 3.6, with the highest quality resolution possible?
- How to optimize
analogRead
? I've read that the fastest way is to use continuousanalogRead
instead of singleanalogRead
? I'm having trouble finding clear examples of what this actually does and how to use it effectively. I definitely could be wrong about it this. - Am I outputting data the best way possible? I was wondering if there would be any reason in my case to use
print()
orprintln()
or if I should be usingflush()
after every cycle
These are a lot of questions, and I don't expect anyone to optimize my code for me, so if you can help point me in the direction of clear material I can use to direct me in this problem.
I'd also really appreciate any other suggestions or insight anyone would like to offer that I may be missing.
This is my very basic code:
const uint8_t RX_CYCLES = 1;
const uint8_t RX_START = 14, RX_END = 21;
const uint8_t TX_START = 0, TX_END = 7;
void setup() {
Serial.begin(115200);
while (!Serial);
for (uint8_t reciever = RX_START; reciever <= RX_END; reciever++) pinMode(reciever, INPUT);
for (uint8_t transmitter = TX_START; transmitter <= TX_END; transmitter++) pinMode(transmitter, OUTPUT);
}
void loop() {
for (uint8_t transmitter = TX_START; transmitter <= TX_END; transmitter++) {
digitalWriteFast(transmitter, HIGH);
for (uint8_t i = 0; i < RX_CYCLES; i++) {
for (uint8_t reciever = RX_START; reciever <= RX_END; reciever++) Serial.println(analogRead(reciever));
}
digitalWriteFast(transmitter, LOW);
}
}