Skip to content

Instantly share code, notes, and snippets.

@ViliusKraujutis
ViliusKraujutis / RotatableTabButtonImageView.java
Last active April 3, 2016 18:41
Do you want to create a tab button with rotatable image view? I wanted to create a button for Playgong's "Explore" tab with spinning compass icon, so I created `RotatableTabButtonImageView` which not only fades in/out icon, but also rotates it as pages are scrolled. Look to `setVividness` method. This method is called from `TabsToolbar` method `…
package com.playgong.view;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
/**
* @author Vilius Kraujutis
* @since 2015-04-29 01:50.
@ViliusKraujutis
ViliusKraujutis / Knock sensor test ky031
Created March 20, 2016 11:57
does not detect knocks on table, but senses shocks while holding in hand
const int ledPin = 31; // define ledPin Interface
const int shockPin = 30; // define the percussion Sensor Interface
int val; // define numeric variables val
long lastKnockTimestamp = 0;
int knockTimeout = 2000;
void setup () {
Serial.begin(9600);
@ViliusKraujutis
ViliusKraujutis / BH1750 light intensity module test.ino
Created March 17, 2016 22:05
I was always getting ‘54612 lux’ measurments. It was mystery, until I found out, that I had to connect my SCL and SDA pins to dedicated 20th and 21st pins on Arduino MEGA 2560.
/*
Example of BH1750 library usage.
This example initalises the BH1750 object using the default
high resolution mode and then makes a light level reading every second.
Connection:
VCC-5v
GND-GND
SCL-SCL(analog pin 5)
@ViliusKraujutis
ViliusKraujutis / PIR and Ultrasonic distance measure.ino
Created March 17, 2016 20:07
Test script to try PIR sensor and Ultrasonic distance measure. Here distance measure method uses precalculated constant 29.1 which is 1 divided by sound speed. Would be good to update this formula to use actual air temperature to measure distance more precisely.
const int pirLedPin = 31;
const int distanceLedPin = 32;
const int pirPin = 33;
const int echoPin = 22;
const int trigPin = 24;
const int distanceMeasureTimeout = 1000;
long lastDistanceMeasureTimestamp = 0;
/* The MIT License (MIT)
Copyright (c) 2014, Marty Glaubitz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@ViliusKraujutis
ViliusKraujutis / adbscreenshot.sh
Created April 26, 2014 08:48
Make screenshot from Android device from command line with ADB
#!/bin/sh
adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > adb-screenshot-$(date +%Y%m%d-%H%M%S).png