Skip to content

Instantly share code, notes, and snippets.

View mjdargen's full-sized avatar

Michael D'Argenio mjdargen

View GitHub Profile
#define NOTE_A0 27
#define NOTE_AS0 29
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
@mjdargen
mjdargen / circuitpy_upload.py
Created December 26, 2020 15:20
# uploads code.py automatically to CircuitPython device on Windows
# uploads code.py automatically to CircuitPython device on Windows
import subprocess
import shutil
# update SOURCE to be the file you want to upload to drive
SOURCE = "C:/Users/Michael/Documents/GitHub/CircuitPython_playground/code.py"
# main function
def main():
@mjdargen
mjdargen / form_letter.py
Last active January 5, 2021 16:58
Automatically generate form letters using docx, docx2pdf, pypdf2
# Windows setup
# pip3 install python-docx
# pip3 install pypdf2
# pip3 install docx2pdf
# linux setup
# sudo apt install unoconv
# pip3 install python-docx
# pip3 install pypdf2
import datetime
@mjdargen
mjdargen / nmap.py
Created December 6, 2020 03:40
Get all current devices on network using nmap in python
import subprocess
import socket
# get ip address
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
IP = s.getsockname()[0]
# use nmap and get response
cmd = f"sudo nmap -sn {IP}/24"
@mjdargen
mjdargen / ultrasonic.cpp
Created November 27, 2020 22:27
Arduino function for retrieving distance in inches for ultrasonic sensor.
// function to retrieve distance from ultrasonic sensor
// distance provided as an integer value in inches
// EXP. int dist_in = get_distance();
// update macros names for ultrasonic sensor pins
// in this case, I used TRIG_PIN, ECHO_PIN
int get_distance() {
// send trigger pulse by setting it high for 10 us
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
@mjdargen
mjdargen / ir_remote.h
Created November 15, 2020 02:14
macros for the codes for each button on IR remote for Elegoo car kit.
/*
* #define macros for the codes
* for each button on IR remote.
*/
#define IR_FORWARD 0xFF629D
#define IR_REVERSE 0xFFA857
#define IR_LEFT 0xFF22DD
#define IR_RIGHT 0xFFC23D
#define IR_OK 0xFF02FD
# ask for input
number = int(input("Please enter an 8-bit binary number: "))
# extract each bit
bit0 = number % 10
bit1 = number % 100 // 10
bit2 = number % 1000 // 100
bit3 = number % 10000 // 1000
bit4 = number % 100000 // 10000
bit5 = number % 1000000 // 100000
@mjdargen
mjdargen / pitches.h
Last active December 11, 2020 17:52
pitches.h - macros to map notes to frequencies
#define REST 0
#define NOTE_A0 27
#define NOTE_AS0 29
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
/*
Create new file called images.h.
Copy the Arduino/C code variables to the right of the matrix picture.
Paste the code into the images.h file
https://github.com/xantorohara/led-matrix-editor
http://xantorohara.github.io/led-matrix-editor/
https://xantorohara.github.io/led-matrix-editor/#003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|00007e99997e0000|000000ffff000000|000000ffff000000|00007e99997e0000|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|003c429999423c00|00007e99997e0000|000000ffff000000|000000ffff000000|00007e99997e0000|003c429999423c00|003c429999423c00|00007e99997e0000|000000ffff000000|000000ffff000000|00007e99997e0000
@mjdargen
mjdargen / crontab_entry.txt
Last active January 13, 2024 21:17
Shell script to periodically reconnect wifi if raspberry pi disconnects.
# ping router every 5 minutes, reconnect if fails
*/5 * * * * /usr/bin/sudo /home/pi/Documents/reconnect_wlan0.sh > /dev/null