Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Nicholson danic85

View GitHub Profile
@danic85
danic85 / RobotLeg.ino
Created February 26, 2023 19:07
Test script for robotic legs
View RobotLeg.ino
/*
* ThreeServos.cpp
*
* Shows smooth movement from one servo position to another for 3 servos synchronously.
* Demonstrates the use of ServoEasingArray and ServoEasingNextPositionArray.
*
* Copyright (C) 2019-2022 Armin Joachimsmeyer
* armin.joachimsmeyer@gmail.com
*
* This file is part of ServoEasing https://github.com/ArminJo/ServoEasing.
@danic85
danic85 / docker-ros-ref-mac.md
Last active January 23, 2023 20:52
ROS2 on MacOS reference commands
View docker-ros-ref-mac.md
@danic85
danic85 / arduino-smart-servo
Created September 10, 2021 19:33
Arduino Smart Servo (continuous servo voltage monitor)
View arduino-smart-servo
// ---------------------------------------------------------------- //
// Arduino Smart Servo (continuous servo voltage monitor)
// Uses a uses a shunt resistor to create a voltage divider that the arduino can monitor.
// When the voltage passes a threshold the servo pauses for a second before continuing.
// https://www.instagram.com/p/CTXWAH9jmJE/
// Tested on September 2020
// Author: Dan Nicholson (github.com/danic85)
// ---------------------------------------------------------------- //
#include <Servo.h>
@danic85
danic85 / arduino-watch-frog-sketch
Last active September 10, 2021 19:18
Arduino Watch Frog (HC-SR04 door distance alarm)
View arduino-watch-frog-sketch
// ---------------------------------------------------------------- //
// Arduino Watch Frog (HC-SR04 door distance alarm)
// Place with sensor facing a closed door and then attach power.
// Alarm will sound if distance to door changes in either direction
// beyond the THRESHOLD. Alarm will not stop until power is disconnected.
// Tested on 10 September 2020
// Author: Dan Nicholson (github.com/danic85)
// ---------------------------------------------------------------- //
#define echoPin 7 // Echo of HC-SR04
@danic85
danic85 / gist:4c48f7dd1d4532049b491c8cd1d47f31
Created December 7, 2016 14:46
Binding lightning:input checkbox value. Must bind to 'checked' not 'value'
View gist:4c48f7dd1d4532049b491c8cd1d47f31
<aura:attribute name="testBoolean" type="Boolean" default="false" />
<lightning:input name="testBoolean" label="Test Boolean" type="checkbox" checked="{!v.testBoolean}" />
View send-error-email.apex
/* Example for sending an email when there is an error on a JSON request */
private static void sendErrorEmail(String method, HttpResponse response, String requestJSON) {
Messaging.SingleEmailMessage message = new Messaging.SingleEmailMessage();
message.toAddresses = new String[] { 'me@example.org' };
message.subject = 'Error in ' + method + ' : ' + response.getStatusCode() + ' - ' + response.getStatus();
if (requestJSON == '' || requestJSON == null)
message.plainTextBody = 'No body';
else message.plainTextBody = requestJSON;
Messaging.SingleEmailMessage[] messages = new List<Messaging.SingleEmailMessage> {message};
Messaging.SendEmailResult[] results = Messaging.sendEmail(messages);
@danic85
danic85 / gist:d56e11650783e7fd6f635e962da3d79b
Created November 23, 2016 10:16
Control visibility of lightning component using slds-hide
View gist:d56e11650783e7fd6f635e962da3d79b
<!-- Component Markup -->
<div aura:id="yourIdentifier">
<c:Your_Component />
</div>
/**
* Controller Method
*/
showComponent : function (component, event, helper) {
$A.util.removeClass(component.find("yourIdentifier"), "slds-hide");
@danic85
danic85 / TestComponent.js
Last active June 14, 2018 11:19
Salesforce Lightning: Setting a conditional default value blocks any further changes to the attribute. Including object will allow changes but only from the object.
View TestComponent.js
<aura:component implements="flexipage:availableForAllPageTypes">
<!-- Simple example of conditional default blocking changes -->
<aura:attribute name="myString" type="string" default="{!if(false, 'Default Val', 'Other Default')}"/>
<aura:attribute name="mySimpleString" type="string" default="Default Val"/>
<!-- Conditional default on object value will update, but will not allow external changes -->
<aura:attribute name="myObj" type="object"/>
<aura:attribute name="myObjString" type="string" default="{!if(empty(v.myObj), 'Default Val', v.myObj.val)}"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
@danic85
danic85 / TestComponent.cmp
Last active June 14, 2018 10:28
Salesforce Lightning: Setting a conditional default value blocks any further changes to the attribute.
View TestComponent.cmp
<aura:component implements="flexipage:availableForAllPageTypes">
<aura:attribute name="myString" type="string" default="{!if(false, 'Default Val', 'Other Default')}"/>
<aura:attribute name="mySimpleString" type="string" default="Default Val"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<div class="slds-card">
{!v.myString} <!-- Will always output 'Other Default', even if changed later by doInit -->
{!v.mySimpleString} <!-- Will be changed to 'Set Directly' by doInit -->
</div>
</aura:component>
@danic85
danic85 / onewire.ino
Created June 12, 2018 12:04
Reading from a 1-wire device (DS28E05) with arduino.
View onewire.ino
/* YourDuino Example: Find Address of a DS18B20 Temperature Sensor
Cut and paste the address to a text file for later use.
V1.1 01/17/2013
Questions: terry@yourduino.com
URL: http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20#Read%20individual
Connections:
DS18B20 Pinout (Left to Right, pins down, flat side toward you)
- Left = Ground
- Center = Signal (Pin 2): (with 3.3K to 4.7K resistor to +5 or 3.3 )