Skip to content

Instantly share code, notes, and snippets.

View reefwing's full-sized avatar

David Such reefwing

View GitHub Profile
@reefwing
reefwing / BluetoothControl.ino
Last active March 20, 2024 21:17
Control a DFRobot Devastator tank via a Romeo BLE (Uno equivalent) using Bluetooth (BLE).
/*
* 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
*
*/
@reefwing
reefwing / SBUS.cpp
Created November 26, 2020 08:47
Modifications to BolderFlight Arduino SBUS library for Nano 33 BLE
#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 */
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.
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;
@reefwing
reefwing / DisplayCM.ino
Created November 1, 2015 03:36
Sharp GP2Y0A02YK0F IR Distance Sensor (20-150 cm) Arduino Library
#include <GP2Y0A02YK0F.h>
GP2Y0A02YK0F irSensor;
int distance;
void setup()
{
Serial.begin(9600);
irSensor.begin(A0); // Assign A0 as sensor pin
}
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("{\"");
@reefwing
reefwing / Main.lua
Created July 6, 2013 04:55
Tutorial 31 - Codea Collision Detection
--# Main
-- Asteroids
--
-- Simple app to demonstrate collision detection using
-- the built in Box2D functionality.
-- Use this function to perform your initial setup
function setup()
#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 },
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;
}
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