Skip to content

Instantly share code, notes, and snippets.

View funvill's full-sized avatar

Steven Smethurst funvill

View GitHub Profile

Principles of Adult Behavior

  1. Be patient. No matter what.
  2. Don’t badmouth: Assign responsibility, not blame. Say nothing of another you wouldn’t say to him.
  3. Never assume the motives of others are, to them, less noble than yours are to you.
  4. Expand your sense of the possible.
  5. Don’t trouble yourself with matters you truly cannot change.
  6. Expect no more of anyone than you can deliver yourself.
  7. Tolerate ambiguity.
  8. Laugh at yourself frequently.
@funvill
funvill / slots.asm
Created November 6, 2022 16:46
Short program with bugs for hackaday supercon 2022 badge, slot machine
init: ; Steven Smethurst, 2022. Based on Hackaday-dice-roll by Tom Nardi
mov r0, 2 ; Set matrix page
mov [0xF0], r0
mov r0, 5 ; Set CPU speed
mov [0xF1], r0
main:
gosub getroll ; Put random number in R1
mov r2, 1 ; Subtract 1 from result to get mem address
@funvill
funvill / gist:5252169
Last active June 17, 2022 02:20
Get the system stats on the raspberry pi or any linux system in python
# Return CPU temperature as a character string
def getCPUtemperature():
res = os.popen('vcgencmd measure_temp').readline()
return(res.replace("temp=","").replace("'C\n",""))
# Return RAM information (unit=kb) in a list
# Index 0: total RAM
# Index 1: used RAM
# Index 2: free RAM
def getRAMinfo():
const int NUMBER_OF_CHANNELS = 8;
Adafruit_INA219 ina219[NUMBER_OF_CHANNELS]{ 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48 };
for (int channel = 0; channel < NUMBER_OF_CHANNELS; channel++) {
ina219[channel].begin();
}
for (int channel = 0; channel < NUMBER_OF_CHANNELS; channel++) {
int busvoltage = ina219[channel].getBusVoltage_V();
int current_mA = ina219[channel].getCurrent_mA();
int main() {
ConnectTCP();
LoadModbusFunctions();
ModbusStack_Init( MODBUS_TCP, sendModbusMessage, recvModbusMessage, currentTime);
ModbusStack_SetSlaveId( MODBUS_SLAVE_ADDRESS );
ModbusStack_RegisterGetValue(getModbusValue);
for(;;) {
ModbusStack_Loop();
}
}
@funvill
funvill / demo100Button.ino
Created March 3, 2019 22:12
The demo 100 from fast led with three buttons
#include "FastLED.h"
FASTLED_USING_NAMESPACE
#include <EasyButton.h>
// FastLED "100-lines-of-code" demo reel, showing just a few
// of the kinds of animation patterns you can quickly and easily
// compose using FastLED.
//
@funvill
funvill / bacnet-iam.cpp
Last active July 31, 2018 18:37
Sending a BACnet I-AM via BACnet stack 1.x version
// http://bacnetstack.com/
// To be a good BACnet Server we should announce our-self when joining a network.
// Generate the IAM message and send it.
char packet[MAXIMUM_BACNET_MESSAGE];
unsigned short payloadSize = fpIAm(SETTING_SERVER_BACNET_NETWORK, (unsigned char *)&deviceOffset, sizeof(unsigned int), packet, MAXIMUM_BACNET_MESSAGE, deviceOffset);
if (payloadSize > 0) {
// Generate the connection string.
BYTE connectionString[10];
sscanf_s("255.255.255.255", "%d.%d.%d.%d", &connectionString[0], &connectionString[1], &connectionString[2], &connectionString[3]);
connectionString[4] = SETTING_BACNET_UDP_PORT / 256;
<BACnetPacket networkType='IP'>
<BVLL function='originalUnicastNPDU'/>
<NPDU control='0x08' version='1'>
<SourceNetwork>389</SourceNetwork>
<SourceAddress length='3'>0x05F17D</SourceAddress>
</NPDU>
<ComplexACKPDU moreFollows='0' originalInvokeId='74' segmentedMessage='0' serviceChoice='readProperty'>
<ReadPropertyACK>
<ObjectIdentifier context='0' datatype='12' objectInstance='389501' objectType='8'>device, 389501</ObjectIdentifier>
<PropertyIdentifier context='1' datatype='9' value='11'>apduTimeout</PropertyIdentifier>
#include "HardwareSerial.h"
HardwareSerial SerialTwo(2);
const char PIN_RS485 = 14;
const unsigned short lineDriveOff = 10;
const unsigned short lineDriveOn = 3;
void setup() {
// initialize serial communications at 9600 bps:
int main() {
ConnectUDP();
SetupCallbacks();
AddDevice(389001) ;
AddObject(389001, ANALOG_INPUT, 101);
AddObject(389001, BINARY_OUTPUT, 102);
AddObject(389001, MULTI_STATE_VALUE, 103);
...