2017-10-31

TCL, array 陣列

Example Code
array set familyName {
    papa Agent7
    momo Agent8
    son Agent9
}



Check ARRAY exist (1: true - 0: false)
# array exists family
# 1


List ARRAY variable name
# array name family
# sonName momoName papaName


Get ARRAY variable content
# array get family
# sonName Agent9 momoName Agent8 papaName Agent7


Resurt
# puts $familyName(papa)
# AgentPAPA

# puts $familyName(momo)
# AgentMOMO

2017-07-19

2017-06-05

Arduino, Vibration Sensor SW420


Example Code
int pin_LED = 13;
int pin_EP = 9;

void setup() {
    Serial.begin(9600);
    pinMode (pin_LED, OUTPUT);
    pinMode (pin_EP, INPUT); //set EP input for measurment
}

void loop() {
    long measurement = TP_init(); //Vibration sensor.
    delay(50); // default is 50
    Serial.print( "key U:" ); Serial.print( " [" ); Serial.print( measurement ); Serial.print( "] " );

    if (measurement > 500){
            digitalWrite(pin_LED, HIGH);
            Serial.print( "Vibration Level: Earthquake." );

    } else if (measurement > 100){
            digitalWrite(pin_LED, HIGH);
            Serial.print( "Vibration Level: Shake Tea." );
            digitalWrite(pin_LED, LOW);
    } else {
            digitalWrite(pin_LED, LOW);
            Serial.print( "Vibration Level: Very Quiet." );
    }
}

long TP_init(){
    delay(10); // default is 10
    long measurement=pulseIn (pin_EP, HIGH); //wait for the pin to get HIGH and returns measurement
    return measurement;
}

2017-01-11

Android, ADB push & pull file.

PUSH / PC to Android
Copy file from PC to Android through ADB shell.
    Syntax | PC C:\ADB\adb push  source_PC_filePath  destination_Android_ filePath
    example: adb push w200b\02-video\color2-green.mp4 data/worktmp

PULL / Android to PC
Copy file from Android to PC through ADB shell.
    Syntax | PC C:\ADB\adb pull source_Android_filePath destination_PC_filePath
    example: adb pull data/worktmp/SoundRecord.png w200b

2017-01-04

Android, NFC.

Turn ON NFC
# service call nfc 6

Turn OFF NFC
# service call nfc 5

Turn ON Anntenna ( Default is ON )
# echo 177 > /sys/class/gpio/export
# echo out > /sys/class/gpio/gpio177/direction

NFC test
# logcat BrcmNfcJni:D | grep 'nfc type='
(nfc tag碰觸,console 會出現以下, 或類似關鍵字出現)
D/BrcmNfcJni(  595): NfcTag::discoverTechnologies (activation): index=0; tech=1; handle=1; nfc type=2

Clear NFC Log
# logcat -c

2016-12-28

Android, Bluetooth.

04. Bluetooth config file.
# cat /data/misc/bluetooth/bt_config.xml

03. Get Bluetooth MAC.
# adb shell settings get secure bluetooth_address
or # settings get secure bluetooth_address
or # service call bluetooth_manager 10  (10 for Android 4, and 12 for Android 5)

02. Get Bluetooth connection via ADB.
# adb shell am start -a android.bluetooth.adapter.action.STATE_CHANGED

01- Turn ON/OFF Bluetooth via ADB.
Turn ON Bluetooth way 1.
step-1
# am start -a android.bluetooth.adapter.action.REQUEST_ENABLE
(but it required user to accept a dialog)

step-2 (dialog pop-up)
# input keyevent 22 & input keyevent 22

step-3
# input keyevent 23

Turn ON Bluetooth way 2.
# service call bluetooth_manager 6
(and no any accept dialog)

Turn OFF Bluetooth.
# service call bluetooth_manager 8

Pi, CLI Audio.

Link reference 1: https://www.raspberrypi.org/documentation/configuration/audio-config.md
Link reference 2: https://www.raspberrypi.org/documentation/usage/audio/

Switch audio output.
# amixer cset numid = 2     (2 is HDMI, 1 is Headphone jack, 0 is automatic by default )

Audio player.
# omxplayer example.mp3
# omxplayer -o hdmi example.mp3     (force output over HDMI)
# omxplayer -o local example.mp3     (force output over headphone jack)

Repeat playback
============
# omxplayer --loop example.mp3

[ Sys Reply ]
Audio codec mp3 channels 1 samplerate 11025 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
Seek to: 00:00:00
Seek to: 00:00:00
Seek to: 00:00:00

[Ctrl + C] Quit player.

2016-12-15

Arduino, RGB sensor TCS34725.


Required library Adafruit_TCS34725.
Turn Off embedded LED, wired TCS34725 of LED pin to Arduino of GND pin.

2016-11-24

Arduino, Light Sensor.


#include

IRsend irsend;

void setup()
{
     Serial.begin(115200);
     pinMode (A0, INPUT);
     pinMode (13, OUTPUT);
}

void loop()
{
     while (Serial.available() == 0);

     int pr = analogRead(A0);
     int val = Serial.read();

     if (val == 81) {
             irsend.sendNEC( 0x1067A857, 32 );
             Serial.println( "NeoSaid: Received Q." );

     } else if (val == 87) {
             irsend.sendNEC( 0x1067A857, 32 );
             Serial.println( "NeoSaid: Received W." );

     } else if (val == 69) {
             Serial.println(pr);

             if (pr > 700) {
                     Serial.println( "NeoSaid: Light Up." );
             } else {
                     Serial.println( "NeoSaid: Light Down." );
             }

             Serial.println( "NeoSaid: Received E." );
     } else {
             Serial.println( "NeoSaid: Nothing found!!!" );
     }

     //Serial.println(val);
}