Skip to content

Instantly share code, notes, and snippets.

@lamegaton
lamegaton / ESP12_UltrasonicSensor_Motors.ino
Last active October 15, 2018 06:25
Simple code for ESP12 with HC-SR04 sensor to avoid obstacles.
//Thanks 4CORE and Jmarlins for helping me.
//NodeMCU.h to map the pin on the motor shield correctly
/*
static const uint8_t D0 = 16;
static const uint8_t D1 = 5;
static const uint8_t D2 = 4;
static const uint8_t D3 = 0;
static const uint8_t D4 = 2;
static const uint8_t D5 = 14;
static const uint8_t D6 = 12;
clear all;
clc;
% Given values
% To calculate W and L use this link:
% https://goo.gl/kYUHc3
% W=11.86*10^-3;
% L=9.06*10^-3;
eps_r = 4.5;
fr = 2.4*10^9;
h = 1.6*10^(-3);
@lamegaton
lamegaton / Romanza.rb
Last active August 31, 2018 05:20
Using this for Sonic Pi
# Welcome to Sonic Pi v3.1
# Romanza sheet is from Ukulele for Dummies
# Translate to Sonic Pi by Son Pham
# Keep learning and creating things!
# use in_thread to keep
#use_synth is for chosing your sound synthesizer, in this demonstration,
#I'm gonna use pluck which is guitar.
#use_bpm is for setting beat per minute for this piece of music.
#I'm gonna choose 90 which is recommended for Romanza
#I use in_thread to keep the next block run concurrently with the in_thread block.
@lamegaton
lamegaton / Jazz_001.rb
Last active August 31, 2018 03:17
#sonicpi Sonic Pi and Jazz
# Welcome to Sonic Pi v3.1
#jazzy
use_synth :pluck
use_bpm 100
live_loop :picking do
# use_synth :pluck
sleep 0.5
play chord(:c,:M7).choose, pan: 1
sleep 0.5
sleep 1
@lamegaton
lamegaton / motorcycleCouple.py
Last active August 31, 2018 05:15
#python This script is basic pygame code to move an object back and forth-ward with background
'''============================================
For this tutorial, i'm gonna make a simple moving object
using pygame. This is based from the chimp tutorial on
pygame website
editor: Son Pham
date: 8/30/2018
files: https://goo.gl/7he7kG
python 3.7.0
=============================================='''
# import modules
@lamegaton
lamegaton / arduinoSpeaker.ino
Created August 31, 2018 05:44
From my blog in 2013
#include "pitches.h"
// Khai báo dãy nốt nhạc:
int melody[] = {NOTE_C7, NOTE_A7,NOTE_G7, NOTE_C7, NOTE_G7,0, NOTE_B7, NOTE_C7};
// Cao độ của nốt: 4 = nốt đen, 8 = nốt móc, etc.:
int noteDurations[] = {4, 8, 8, 3,4,6,10,10 };
void setup() {
// Chơi tất cả các nốt:
for (int thisNote = 0; thisNote < 8; thisNote++) {
/* Để tính cao độ, ta lấy 1 giây chia cho nốt VD: nốt đen = 1000 / 4, nốt móc = 1000/8,...*/
int noteDuration = 1000/noteDurations[thisNote];
@lamegaton
lamegaton / tts_python.py
Created September 3, 2018 07:48
#python use gtts and pygame to play sound directly
from gtts import gTTS
from io import BytesIO
import pygame
mp3_fp = BytesIO()
tts = gTTS("Trước khi bắt đầu, xin lưu ý \
rằng khi market size của bạn \
nhỏ không có nghĩa rằng đó là \
một mô hình kinh doanh không tốt", 'vi')
@lamegaton
lamegaton / SwitchExample.c
Created September 13, 2018 19:33
Example of Switch
/*Example from book the C programing language
* by Brian W.Kernighan and Dennis M. Ritchie
*/
#include <stdio.h>
int main(){
int c, i, nwhite, nother, ndigit[10];
nwhite = nother = 0;
//reset the array to 0
for (i = 0; i < 10; i++)
@lamegaton
lamegaton / timeLeft.py
Created September 14, 2018 08:02
Calculate and print out time left on earth
import time
from datetime import date
#def count_time_left():
today =date.today()
while True:
yourMonth = int(input("Enter your Month of birth MM: "))
if yourMonth >12 or yourMonth < 0:
print('please try MM again!')
@lamegaton
lamegaton / esp_max_LED.ino
Created October 17, 2018 22:50
use ESP8266 + Max7219 LED matrix, the speed is very slow, need to be improved
// credits to https://github.com/MajicDesigns/MD_MAX72XX
#include <ESP8266WiFi.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
//Declare hardware
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN 14 // or SCK