#include /* * Declare the msg variable as the Message data type * Message comprises a structure that that describes the identifiers of the message being transferred */ Message msg; /* * Declare the bus variable as the OrbicraftBus data type * OrbicraftBus is a class describing interaction between Arduino and Orbicraft construction set bus */ OrbicraftBus bus; // Declare the msgSize variable to hold the message being transferred int16_t msgSize = 0; // Declare the pin number to sense readings int data_pin = A0; // These pin will be used for readouts from the sensor void setup() { Serial1.begin(9600); // Define data transfer rate over Serial1 (Check Serial2.begin(9600)) } void loop() { msgSize = bus.takeMessage(msg); // Try to read the message using the takeMessage method if (msgSize > 0){ //If there is a message… switch (msg.id){//Process in a particular manner depending on message ID // Consider the case with ID 2 case 0x02:{ String data = String(Sensor_data()); // Store readings obtained from Sensor_data() in the data variable bus.sendMessage(bus.obcAddress, 0, data); // пSend the contents of the data variable to the OCC break; } } } } uint16_t Sensor_data(void){ uint16_t data = analogRead(data_pin); //Read illuminance values from the sensor return data; } /* * The following block of code must always be appended to the program. * The function is called automatically and is necessary for message processing. */ void serialEvent2() { bus.serialEventProcess(); }