Skip to content

Instantly share code, notes, and snippets.

View mjdargen's full-sized avatar

Michael D'Argenio mjdargen

View GitHub Profile
/*
Doorbell
Passive Buzzer/Piezoelectric Speaker
* Digital output 8
* Other end of speaker connected to GND
Pushbutton (for doorbell):
* Digital input 2
// send trigger pulse by setting it high for 10 us
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Call pulseIn function to wait for High pulse
// result will be time in microseconds until pulse is detected
long duration = pulseIn(ECHO_PIN, HIGH);
// Sound travels at 1115 feet per second
# Run this cell only once if you are having issues with your input/output...
# window overflowing and scrolling to the left and right horizontally.
# This code is a very hacky way of trying to adjust this.
# It resizes colab output window so it doesn't overflow
from IPython.display import HTML, display
def set_css():
display(HTML('''
<style>
pre {
# pip install pyautogui
import pyautogui
# pip install pillow
from PIL import ImageGrab
import time
def click(key):
pyautogui.keyDown(key)
return
# import the math library for flooring function
import math
# define a new function that always rounds up if the digit is 5.
# call the function by saying: new_round(num, decimals)
# where num is the number you want to round and decimals is the
# number of digits after decimal point.
# Exp: new_round(2.5, 0) -> 2
# Exp: new_round(2.75, 1) -> 2.8
def new_round(num, decimals=0):
@mjdargen
mjdargen / keypad.ino
Created July 30, 2020 16:57
4x4 Membrane Switch Keypad for Arduino
/*
* Demo Code for 4x4 Membrane Switch Keypad
*/
#include <Keypad.h>
// initialization of the 4x4 keypad
const byte ROWS = 4; // four rows
const byte COLS = 4; // four columns
// define the two-dimensional array on the buttons of the keypads
@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
/*
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 / 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
# 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