This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* BluetoothControl: Control a DFRobot Devastator tank via a Romeo BLE | |
* (Uno equivalent) using Bluetooth (BLE). | |
* | |
* Compatible with iPhone app AVA BLE - https://itunes.apple.com/au/app/ava-ble-remote/id1073023233?mt=8 | |
* | |
* Version 0.3, August, 2018 | |
* Copyright 2018 David Such | |
* | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if defined(ARDUINO_ARCH_NRF52840) | |
// Arduino Nano 33 BLE | |
// Serial1.begin() wont set a non-standard baud rate and anything but 8N1 crashes Mbed OS. | |
const uint32_t CONFIG = 0x000000F; | |
const uint32_t sbusBaudRate = 0x19114A7; | |
uint32_t *baudRateRegister = ( uint32_t * )0x40002524; | |
uint32_t *configRegister = ( uint32_t * )0x4000256C; | |
#endif | |
/* starts the serial communication */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ForceLookup { | |
uint16_t voltage; // millivolts (mV) | |
uint16_t force; // grams (g) | |
}; | |
ForceLookup table[FLT_SIZE] = { {0, 0}, {900, 20}, {1400, 50}, {1750, 100}, {2250, 200}, {2500, 310}, | |
{2800, 450}, {3000, 580}, {3200, 710}, {3400, 900}, {3450, 1000} }; | |
float interpolate(uint16_t adc_mV) { | |
// Based on ADC voltage (mV), lookup the force (g) and interpolate between adjacent values if required. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void parseCommand() { | |
char *cmdPtr = rx.getCommand(); | |
switch(rx.hash(cmdPtr) % HASH_SIZE) { | |
case xIMU3_ping: | |
rx.sendPing(pingPacket); | |
break; | |
case xIMU3_deviceName: | |
rx.sendResponse("deviceName", "Arduino"); | |
break; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <GP2Y0A02YK0F.h> | |
GP2Y0A02YK0F irSensor; | |
int distance; | |
void setup() | |
{ | |
Serial.begin(9600); | |
irSensor.begin(A0); // Assign A0 as sensor pin | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void sendResponse(char *key, char *value) { | |
Serial.print("{\""); | |
Serial.print(key); | |
Serial.print("\":\""); | |
Serial.print(value); | |
Serial.print("\"}\r\n"); | |
} | |
void sendResponse(char *key, int value) { | |
Serial.print("{\""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--# Main | |
-- Asteroids | |
-- | |
-- Simple app to demonstrate collision detection using | |
-- the built in Box2D functionality. | |
-- Use this function to perform your initial setup | |
function setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define BAD_ID -1 | |
typedef struct { | |
char *key; | |
int val; | |
} msp_commands_t; | |
static msp_commands_t lookupTable[] = { | |
{ "MSP_API_VERSION", MSP_API_VERSION }, { "MSP_FC_VARIANT", MSP_FC_VARIANT }, { "MSP_FC_VERSION", MSP_FC_VERSION }, { "MSP_BOARD_INFO", MSP_BOARD_INFO }, | |
{ "MSP_BUILD_INFO", MSP_BUILD_INFO }, { "MSP_NAME", MSP_NAME }, { "MSP_SET_NAME", MSP_SET_NAME }, { "MSP_IDENT", MSP_IDENT }, { "MSP_STATUS", MSP_STATUS }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unsigned long hash(unsigned char *str) { | |
unsigned long hash = 5381; | |
int c; | |
while (c = *str++) | |
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ | |
return hash; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void checkForCommand() { | |
char buffer[BUFFER_SIZE]; | |
// Check for xIMU3 Command Messages | |
if (Serial.available() > 0) { | |
// read the incoming bytes: | |
int blen = Serial.readBytesUntil(STOP_BYTE, buffer, BUFFER_SIZE); | |
bool cmdFound = false; | |
// Command character count |
NewerOlder