Skip to content

Instantly share code, notes, and snippets.

View lvidarte's full-sized avatar

Leo Vidarte lvidarte

View GitHub Profile
@lvidarte
lvidarte / boot.py
Last active August 22, 2016 11:45
Boot script for Micropython running on NodeMCU
# This file is executed on every boot (including wake-boot from deepsleep)
import gc
gc.collect()
import network
ap_if = network.WLAN(network.AP_IF)
ap_if.config(essid="RGBLamp", password="12345678")
@lvidarte
lvidarte / template.py
Created August 22, 2016 11:33
RGB Lamp template for NodeMCU with Micropyhton
html = """<!DOCTYPE html><html><head><title>RGBLamp</title><style type="text/css">body{background:#222;color:#aaa;font-family:monospace;}table,input,h1{font-size:4em;}input[type=range]{width:1em;}#r_color,#g_color,#b_color{width:1em;height:1em;background:#000;}#r_value,#g_value,#b_value{min-width:2em;}#rgb{width:4em;height:4em;background:#000;margin-left:.5em;}.box{border:solid .1em #111;-webkit-border-radius:6;-moz-border-radius:6;border-radius:6px;}.btn{color:#aaa;font-size:1em;font-family:monospace;background:#333;padding:10px 20px 10px 20px;margin-top:.5em;text-decoration:none;}.btn:hover{background:#000;text-decoration:none;}</style><script type="text/javascript">function showInfo(){var r=document.forms[0].r.value;var g=document.forms[0].g.value;var b=document.forms[0].b.value;showColor('r_color',255,invertColor(r),invertColor(r));showColor('g_color',invertColor(g),255,invertColor(g));showColor('b_color',invertColor(b),invertColor(b),255);showColor('rgb',r,g,b);showValue('r_value',r);showValue('g_value',
@lvidarte
lvidarte / main.py
Last active August 22, 2016 11:48
RGB Lamp server for NodeMCU with Micropyhton
"""
RGBLamp
-------
HTTP daemon for Micropython running on NodeMCU.
@author Leo Vidarte <[email protected]>
@date 22-08-2016
"""
import socket
from gpiozero import MotionSensor, Buzzer
import time
pir = MotionSensor(22)
bz = Buzzer(17)
print("Waiting for PIR to settle")
pir.wait_for_no_motion()
while True:
-- rgb.lua
PIN_R = 3
PIN_G = 2
PIN_B = 1
function led(r, g, b)
pwm.setduty(PIN_R, r)
pwm.setduty(PIN_G, g)
pwm.setduty(PIN_B, b)
end
@lvidarte
lvidarte / sketch.ino
Last active March 28, 2016 02:02
Arduino interrupt example
#include <stdio.h>
#include <LiquidCrystal.h>
#define BUTTON_PIN 2
#define LCD_LINE_LENGTH 17
volatile int state = 1;
static char buffer0[LCD_LINE_LENGTH];
static char buffer1[LCD_LINE_LENGTH];
@lvidarte
lvidarte / index.html
Last active December 18, 2015 21:43 — forked from anonymous/index.html
Angular providers
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<meta charset="utf-8">
</head>
<body ng-app="app">
<div ng-controller="ctrl">
Score: {{ score.points }}
@lvidarte
lvidarte / index.html
Last active December 18, 2015 18:54 — forked from anonymous/index.html
$scope.$watch function
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<meta charset="utf-8">
</head>
<body ng-app="app">
<div ng-controller="SumController">
<select ng-model="value" ng-options="n for n in [1, 2, 3, 4, 5]"></select>
@lvidarte
lvidarte / index.html
Last active December 18, 2015 18:54 — forked from anonymous/index.html
Angular $scope inheritance
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
<meta charset="utf-8">
</head>
<body ng-app="app">
<div ng-controller="NameController">
{{ name }}
@lvidarte
lvidarte / odoo.py
Last active November 16, 2015 22:14
import xmlrpclib
url = 'http://odoo.staging.coquelux.com.br:8069'
username = 'leonardo.vidarte@**********.com'
password = '*********'
db = 'erp_odoo'
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})