Skip to content

Instantly share code, notes, and snippets.

View gazolla's full-sized avatar

Sebastiao Gazolla Jr gazolla

View GitHub Profile
@gazolla
gazolla / All LEDS blinking
Created December 26, 2014 00:27
Arduino Multi function shield
int led1 = 13;
int led2 = 12;
int led3 = 11;
int led4 = 10;
void setup()
{
// initialize the digital pin as an output.
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
@gazolla
gazolla / Switches
Created December 26, 2014 00:29
Arduino Multi function shield - Switches example
const byte LED[] = {13,12,11,10};
#define BUTTON1 A1
#define BUTTON2 A2
void setup()
{
// initialize the digital pin as an output.
/* Set each pin to outputs */
pinMode(LED[0], OUTPUT);
@gazolla
gazolla / Potentiometer and led
Last active August 29, 2015 14:12
Arduino Multi function shield - Potentiometer and led
const byte LED[] = {13,12,11,10};
#define Pot1 0
void setup()
{
Serial.begin(9600);
// initialize the digital pin as an output.
/* Set each pin to outputs */
pinMode(LED[0], OUTPUT);
pinMode(LED[1], OUTPUT);
@gazolla
gazolla / gist:7a04a433902ff6c7e55b
Created December 26, 2014 00:34
Arduino Multi function shield - Read pot and display value on display
/* Define shift register pins used for seven segment display */
#define LATCH_DIO 4
#define CLK_DIO 7
#define DATA_DIO 8
#define Pot1 0
/* Segment byte maps for numbers 0 to 9 */
const byte SEGMENT_MAP[] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0X80,0X90};
/* Byte maps to select digit 1 to 4 */
@gazolla
gazolla / gist:76835584c7205218c8f6
Created December 27, 2014 02:47
Auto Layout - how to follow superview
NSDictionary* views = @{@"collectionView": self.collection};
NSArray* sHorizontal = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[collectionView]|"
options:0
metrics:nil
views:views];
NSArray* sVertical = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[collectionView]|"
options:0
@gazolla
gazolla / StreamReader.swift
Last active May 20, 2016 15:07
The following Swift code was created by Martin R. (http://stackoverflow.com/users/1187415/martin-r) and it should be used to read files line-by-line as explained in http://stackoverflow.com/questions/24581517/read-a-file-url-line-by-line-in-swift
class StreamReader {
let encoding : UInt
let chunkSize : Int
var fileHandle : NSFileHandle!
let buffer : NSMutableData!
let delimData : NSData!
var atEof : Bool = false
@gazolla
gazolla / gist:00278db86636a35ac958
Created April 11, 2015 18:48
Convert serial.read() into a useable string using Arduino
char inData[20]; // Allocate some space for the string
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character
void setup() {
Serial.begin(9600);
Serial.write("Power On");
}
char Comp(char* This) {
@gazolla
gazolla / HTTP.swift
Last active September 20, 2016 15:51
HTTP encapsulation
//
// HTTP.swift
// TableTest2
//
// Created by Gazolla on 22/05/16.
// Copyright © 2016 Gazolla. All rights reserved.
//
import Foundation
import UIKit
func quicksort<T:Comparable>(list:[T])->[T]{
if list.isEmpty {
return list
}
let pivot = list[list.count/2]
let equal = list.filter{ $0 == pivot }
let less = list.filter{ $0 < pivot }
let greater = list.filter{ $0 > pivot }
return quicksort(less) + equal + quicksort(greater)
}
@gazolla
gazolla / reverse.swift
Last active May 24, 2016 03:37
Reverse all Strings from a sentence
let sentence = "Hello, My name is Bob"
let result = sentence.characters.reversed().map { String($0) }.joined(separator:"")
print(result)