Stap 4: Programmeren van de Arduino
Als u nauwkeurige monsters, worden de timer interrupts gebruikt op de Arduino dus de programmastructuur van dit een beetje anders dan andere programma van de Arduino's die u uitzien aan hebt gewerkt. Dit Instructable heeft veel meer details op de Arduino timers, als u geïnteresseerd bent:
De code kan worden gedownload van GitHub (https://github.com/MoreCoffee12/SerialScope/tree/m...), het zip-bestand gekoppeld aan deze stap of getypt uit de onderstaande lijst.
// Firmware to capture 2-channels of data and send it out over BlueTooth. // This implementation is designed to provide data to the Windows Phone 8 // Application // // Software is distributed under the MIT License, see ArduinoFirmware_License.txt // for more details. // This library provides a frame structure // for the data. #include <minsegbus.h> MinSegBus mbus; // The SoftwareSerial library is used to provide // data to the Bluetooth module. #include <SoftwareSerial.h> SoftwareSerial BTSerial(10, 11); // RX | TX #define maxbuffer 0x0400 #define ADCChannels 0x0002 //storage variables boolean toggle0 = 0; // Define the ADC int analogPinCh1 = 0; int analogPinCh2 = 1; bool bOutput; // Buffers unsigned short iUnsignedShortArray[ADCChannels*2]; unsigned char cBuff[maxbuffer]; // MinSegBus vaiiables unsigned char iAddress; unsigned short iUnsignedShort; unsigned int iBytesReturned; unsigned int iErrorCount; unsigned int iIdx; void setup() { // Serial port setup Serial.begin(115200); BTSerial.begin(115200); // Definitions for the MinSegBus iAddress = 0x000; // Tattle tale pins, used to confirm timing pinMode(9, OUTPUT); // Get two samples before sending the frame bOutput = false; // Timer setup. Begin by disabling the interrupts // Reference: