Sunday, March 14, 2021

Raspberry Pi C program for three LED

/*

 * blink.c:

 * Standard "blink" program in wiringPi. Blinks an LED connected

 * to the first GPIO pin.

 *

 * Copyright (c) 2012-2013 Gordon Henderson. <projects@drogon.net>

 ***********************************************************************

 * This file is part of wiringPi:

 * https://projects.drogon.net/raspberry-pi/wiringpi/

 *

 *    wiringPi is free software: you can redistribute it and/or modify

 *    it under the terms of the GNU Lesser General Public License as published by

 *    the Free Software Foundation, either version 3 of the License, or

 *    (at your option) any later version.

 *

 *    wiringPi is distributed in the hope that it will be useful,

 *    but WITHOUT ANY WARRANTY; without even the implied warranty of

 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

 *    GNU Lesser General Public License for more details.

 *

 *    You should have received a copy of the GNU Lesser General Public License

 *    along with wiringPi.  If not, see <http://www.gnu.org/licenses/>.

 ***********************************************************************

 */


#include <stdio.h>

#include <wiringPi.h>


// LED Pin - wiringPi pin 0 is BCM_GPIO 17.


#define LED0 0

#define LED1    1

#define LED2    2


int main (void)

{

 int i;

  printf ("Raspberry Pi blink 10 times\n") ;


  wiringPiSetup () ;

  pinMode (LED0, OUTPUT) ;

  pinMode (LED1, OUTPUT) ;

  pinMode (LED2, OUTPUT) ;


  for (i=1;i<10;i++)

  {

    digitalWrite (LED1, LOW) ;  // Off

    digitalWrite (LED0, HIGH) ; // On

    delay (50) ; // mS

    digitalWrite (LED0, LOW) ; // Off

    digitalWrite (LED1, HIGH) ; // On

    delay (50) ;               // mS

    digitalWrite (LED1, LOW) ;  // Off

    digitalWrite (LED2, HIGH) ; // On

    delay (50) ;               // mS

    digitalWrite (LED2, LOW) ;  // Off

    digitalWrite (LED1, HIGH) ; // On

    delay (50) ;

  }

    digitalWrite (LED1, LOW) ;  // Off


  return 0 ;

}


tkinter python3

Raspberry Pi 

Python3 

Tcl 8.6

26pin GPIO 

GPIO BCM 17,18 and 27


 ## Toggle an LED when the GUI button is pressed ##

# Use only RPi.GPIO to avoid spurious errors

from tkinter import *

import tkinter.font

import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BCM)


### HARDWARE DEFINITIONS ###

led0=17

led1=18

led2=27

GPIO.setup(led0,GPIO.OUT)

GPIO.output(led0, False)

GPIO.setup(led1,GPIO.OUT)

GPIO.output(led1, False)

GPIO.setup(led2,GPIO.OUT)

GPIO.output(led2, False)


### GUI DEFINITIONS ###

win = Tk()

win.title("LED Toggler")

myFont = tkinter.font.Font(family = 'Helvetica', size = 12, weight = "bold")



### Event Functions ###

def redledToggle():

    if GPIO.input(led0):

        GPIO.output(led0, False)

        ledButton["text"]="RED on" # Change only the button text property

    else:

        GPIO.output(led0, True)

        ledButton["text"]="RED off"

        

def greenledToggle():

    if GPIO.input(led1):

        GPIO.output(led1, False)

        led1Button["text"]="GREEN on" # Change only the button text property

    else:

        GPIO.output(led1, True)

        led1Button["text"]="GREEN off"


def blueledToggle():

    if GPIO.input(led2):

        GPIO.output(led2, False)

        led2Button["text"]="BLUE on" # Change only the button text property

    else:

        GPIO.output(led2, True)

        led2Button["text"]="BLUE off"

        

def close():

    GPIO.cleanup()

    win.destroy()


### WIDGETS ###


# Button, triggers the connected command when it is pressed

ledButton = Button(win, text='RED on', command=redledToggle, bg='bisque2', height=3, width=24)

ledButton.grid(row=0,column=1)

led1Button = Button(win, text='GREEN on', command=greenledToggle, bg='bisque2', height=3, width=24)

led1Button.grid(row=2,column=1)

led2Button = Button(win, text='BLUE on', command=blueledToggle, bg='bisque2', height=3, width=24)

led2Button.grid(row=4,column=1)


exitButton = Button(win, text='Exit', command=close, bg='red', height=1, width=6)

exitButton.grid(row=6, column=1)


win.protocol("WM_DELETE_WINDOW", close) # cleanup GPIO when user closes window


win.mainloop() # Loops forever


Sunday, April 12, 2020

Buddhist Prayer for Meditation

Tharpa Publications
Ulverston, England
Glen Spey, New York

Liberating Prayer
Praise to Buddha Sakyamuni

O Blessed One, Shakyamuni Buddha,
Precious treasury of compassion,
Bestower of supreme inner peace,
You, who love all beings without exception,
Are the source of happiness and goodness;
And you guide us to the liberating path.
Your body is a wish fulfilling jewel,
Your speech is supreme, purifying nectar
And your mind is refuge for all living beings.
With folded hands I turn to you,
Supreme unchanging friend,
I request from the depths of my heart:
Please give me the light of your wisdom
To dispel the darkness of my mind
And to heal my mental continuum.
Please nourish me with your goodness,
That I in turn may nourish all beings
With an unceasing banquet of delight.
Through your compassionate intention,
Your blessings and virtuous deeds,
And my strong wish to rely upon you,
May all suffering quickly cease
And all happiness and joy be fulfilled;
And may holy Dharma flourish for evermore.


Introduction

We all have the potential to gain realizations of all the stages of the path to enlightenment. These potentials are like seeds in the field of our mind, and our meditation practice is like cultivating these seeds. However, our meditation practice will be successful only if we make good preparations beforehand.

If we want to cultivate external crops, we begin by making careful preparations. First, we remove from soil anything that might obstruct their growth, such as stones and weeds Second, we enrich the soil with compost or fertilizer to give it the strength to sustain.growth. Third, we provide warm,hoist
conditions to enable the seeds to germinate and the plants to grow. In the same way, to cultivate our inner crops of Dharma realizations we must also begin by making careful preparations. First, we must purify our mind to eliminate the negative karma we have accumulated in the past, because if we do not purify this karma it will obstruct the growth of Dharma realizations. Second, we need to give our mind the strength to support the growth of Dharma realizations by accumulating it. Third, we need to activate and sustain the growth of Dharma realizations by receiving the blessings of the holy beings.

The brief prayers that follow contain the essence of these three preparations. For more information on them, see The Meditation Handbook or Joyful Path of Good Fortune.

Prayers for Meditation

Going for refuge
I and all sentient beings, until we achieve
enlightenment,
Go for refuge to Buddha, Dharma, and Sangha.
(3x,7x,100x, or more)

Generating bodhichitta
Through the virtues I collect by giving and other
perfections,
May I become a Buddha for the benefit of all. (3x)

Generating the four immeasurables
May everyone be happy,
May everyone be free from misery,
May no one ever be separated from their happiness,
May everyone have equanimity, free from hatred and
attachment.

Visualizing the Field for Accumulating Merit
In the space before me is the living Buddha Shakyamuni
surrounded by all the Buddhas and Bodhisattvas, like
the full moon surrounded by stars.

Prayer of seven limbs
With my body, speech, and mind, humbly I prostrate,
And make offerings both set out and imagined.
I confess my wrong deeds from all time,
And rejoice in the virtues of all.
Please stay until samsara ceases,
And turn the Wheel of Dharma for us.
I dedicate all virtues to great enlightenment.

Offering the mandala
The ground sprinkled with perfume and spread witir
flowers,
The Great Mountain, four lands, sun and moon,
Seen as a Buddha Land and offered thus,
May all beings enjoy such Pure Lands.
I offer without any sense of loss
The objects that give rise to my attachment, hatred,
and confusion,
My friends, enemies, and strangers, our bodies and
enjoyments;
Please accept these and bless me to be released directly
from the three poisons.

IDAM GURU RATNA MANDALAKAM NIRYATAYAMI

Prayer of the Stages of the Path
The path begins with strong reliance
On my kind Teacher, source of all good;
O Bless me with this understanding
To follow him with great devotion.

This human life with all its freedoms,
Extremely rare, with so much meaning;
O Bless me with this understanding
All day and night to seize its essence.

My body, like a water bubble,
Decays and dies so very quickly;
After death come results of karma,
Just like the shadow of a body.

With this firm knowledge and remembrance
Bless me to be extremely cautious,
Always avoiding harmful actions
And gathering abundant virtue.

Samsara's pleasures are deceptive,
Give no contentment, only torment;
So please bless me to strive sincerely
To gain the bliss of perfect freedom.

O Bless me so that from this pure thought
Come mindfulness and greatest caution,
To keep as my essential practice
The doctrine's root, the Pratimoksha.

Just like myself all my kind mothers
Are drowning in samsara's ocean;
O So that I may soon release them,
Bless me to train in bodhichitta.

But I cannot become a Buddha
By this alone without three ethics;
So bless me with the strength to practice
The Bodhisattva's ordination.

By pacifying my distractions
And analyzing perfect meanings,
Bless me to quickly gain the union
Of special insight and quiescence.

When I become a pure container
Through common paths, bless me to enter
The essence practice of good fortune,
The supreme vehicle, Vajravana.

The two attainments both depend on
My sacred vows and my commitments;
Bless me to understand this clearly
And keep them at the cost of my life.

By constant practice in four sessions,
The way explained by holy Teachers,
O Bless me to gain both the stages,
Which are the essence of the Tantras.

May those who guide me on the good path,
And my companions all have long lives;
Bless me to pacify completeiy
All obstacles, outer and inner.

May I always find perfect Teachers,
And take delight in holy Dharma,
Accomplish all grounds and paths swiftly,
And gain the state of Vajradhara.

Receiving blessings and purifying
From the hearts of all the holy beings, streams of light
and nectar flow down, granting blessing and purifying.
At this point we begin the actual comtemplation and meditation,
After the meditation we dedicate our merit while reciting the following prayers:

Dedication prayers
Through the virtues I have collected
By practising the stages of the path,
May all living beings find the opportunity
To practise in the same way.

May everyone experience
The happiness of humans and go_ds,
And quickly attain enlightenment,
So that samsara is finally extinguished.

Prayers for the Virtuous Tradition
So that the tradition of Je Tsongkhapa,
The King of the Dharma, may fiourish,
May all obstacles be pacified
And may all favourable conditions abound.

Through the two collections of myself and others
Gathered throughout the three times,
May the doctrine of Conqueror Losang Dragpa
Flourish for evermore.

The nine-line Migtsema prayer
Tsongkhapa, crown ornament of the scholars of the
Land of the Snows, '
You are Buddha Shakyamuni and Vajradhara, the
source of all attainments,
Avalokiteshvara, the treasury of unobservable
compassion,
Manjushri, the supreme stainless wisdom,
And Vajrapani, the destroyer of the hosts of maras"
O Venerable Guru-Buddha, synthesis of all Three
Jewels,
With my body, speech, and mind, respectfullv I make
requests:
Please grant your blessings to ripen and liberate myself
and others,
And bestow the common and supreme attainments.
(3x)
Colophon: These prayers were compiled from traditional
sources by Venerable Geshe Kelsang Rinpoche.

Friday, April 3, 2020

Covid19 : What is flattening curve?

It is not zero case. But to reduce the speed of infection so that hospital have resources to cope with people sick with Covid19.

The reason is there's no herd immunity and vaccine.

But we have a chance that 60% people in the world are immune and thus the other 40% will have less chance to get covid19. Unfortunately that would mean 60% will need to be infected and hopefully this 60% is healthy and have mild symptom only and then straight recover.

Covid19 : Is panic buying good or bad?

Panic buying is always painted in bad light. I am also exponent of panic buying. But I always look things from many angles.

Let's talk about bad side:
1. Create artificial shortage causing other people unable to buy it. Example is egg hoarding causing other people unable to buy.
2. Wastage due to expiry if hoard too much fresh produce

How about the good side:
1. Reduce frequency of travel which indirectly reduce covid19 transmission

So there's not everything black and white.

Thursday, April 2, 2020

KLSE : Energy stocks fly today

I was planning to buy energy stock today but unfortunately I was still investigating when the whole sector went up:-

This is due to Trump:-
Let's try again!

Wednesday, April 1, 2020

Covid19 in Malaysia

This will be updated time to time

January - no more influenza vaccine (stock finish). Not related to Wuhan Virus bur since the symptom are the same, some people will link this two. At this time, people still call it Wuhan Virus. 

February - news come out from China about lockdown and for Malaysia, we start to get a bit scared. More people are infected. But recovery is 100%. Nothing is alarming. At start, it was foreigners. Then some locals. Still, everyone survived. 

March - after  backdoor government is formed, this is when shit start to hit the fan. The whole country lockdown due to Tabligh infection rate goes up to 10% and people start dying. Mostly dead are diabetes and high blood pressure patient. Lockdown is called MCO here. Movement control as they said. But its really a lock since nobody can go to work (except exempted company). 

April - to be continued.... 
Legacy software on Windows 10

I didn't realise Excel 2007 cannot do proper ALT-TAB.

Here is the solution:-

1. Open Registry Editor (Win+R followed by regedit)
2. Go to: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer
3. Create a new 32-bit DWORD value named AltTabSettings and set it to 1
4. Sign out and sign back in again (or restart)

Thanks to:-


Sunday, May 21, 2017

Another Product Dies with Audio Cassette

Cassette have died a long time ago. Probably in the 90s. It's a bad format. Cassette head that reads the cassette always need cleaning. And we always use Swan Alcohol to clean it. There might be other brand but this ubiquitous cassette head cleaner is always sold it every cassette shop.

Aside from using it to clean cassette head, this alcohol solution can also be used to remove sticky plastic. Very useful for Transformers toys that have gone sticky and other plastic items like phones and case.

So while the death of cassette have been long, the swan alcohol still sold for years until last year when I tried to find it in Penang, it was no where to be found. Not even Kulim. My Amazon HDX case is sticky and I need this alcohol to remove the sticky portion.

After searching high and low, I managed to find it in Mahkota Parada in Malacca. There's a shop that still sell cassette tape and I am shocked they still have loads of Swan Alcohol. Thanks to them, I can now clean my sticky plastic. Bought 2 bottle at RM6 per bottle.

Awesome! This show that Malacca is great place to get old items. LOL.

Sunday, March 5, 2017

Ultimate Guide to Mi Box 3 Root (MDZ-16-AA)

Step 1 - Downgrade firmware
Read this site : http://en.miui.com/thread-323779-1-1.html
Firmware for MDZ-16-AA (https://yadi.sk/d/HfBua33Tu25s6)
Tips to enter recovery mode:-

  1. Make sure your bluetooth remote almost touch the mi both white light area
  2. Try a few times if not able to go into recovery mode

Step 2 - Rooting (with Kingoroot)

  1. Install Kingoroot and ADB universal driver (can also install Mi PC Suite which also install the ADB driver)
  2. Enable ADB mode in Mi Box and disable Auto Update
  3. PC connect to Mi Box using USB A to MicroUSB + MicroUSB to USB A adapter. USB A to USB A cable might not work.
  4. Kingoroot will detect Mi Box and follow the instruction. In Mi Box, it also ask you to install some Battery Apps. 
  5. You're now rooted
Step 3 - Rooting (with Genius root)
  1. If your Mi Box is hang at GITV bluescreen, you need to to Step 1 again.
  2. Enable ADB again in Mi Box
  3. Then install Root Genius (http://rootgenius.com/)
  4. Install whatever app in the Mi Box that Root Genius ask you.
  5. You're now rooted.
If you want to have Android TV with Google Cast functionality:-
https://www.youtube.com/watch?v=ACzgVoO76c0&t=181s
GoogleTV TWRP - https://goo.gl/OM9dza


Saturday, April 30, 2016

What to do in Munich, Germany

Germany is not English speaking country. It's a bit difficult for me because everything in German.

So I compiled a list of thing to do in Munich based on my experience. I might be wrong.

For a start, buy a weekly ticket with 1 day extra at the arrival and departure.
Weekly Euro21.10 (four ring inside Munich)
Arrival Euro6.40 (going to Munich) - special price
Departure Euro6.40 (going to airport) - special price

Stay near U Bahn or S Bahn is good idea. U Bahn is underground train while S Bahn is sometimes on the ground. S Bahn also mostly travel between OstBanhNof and HaupBahnNof.

Place To Shop
1. Souvenir - Marienplatz near HofBrauHaus/HardRockCafe.
2. Chocolate and cheap item - Kaufland at EinKauf Zentrum. This is something like Walmart or Tesco.
3. Clothes - probably TK Maxx and nearby shops in Neuhauser Str. 21, 80331 München, Germany
4. Window shopping - Maximilianstraße where money is too much. Also around Marienplatz all the way to Funf Hof is shopping district.

What to see
1. Deutsche Museum - can buy 3 ticket at Euro 16. Else just buy one main ticket to main Museum near Isartor. The main one can take you 1 whole day
2. BMW Museum and BMW Welt
3. Shopping complex is called EinKauf Zentrum. You can plan to go Olympic EinKauf Zentrum, Pasing, Neuperlach etc.

Monday, April 18, 2016

How to take train from Munich airport to Villach

1. Buy ticket from counter one floor below arrival floor. Print the itinerary before you pay.
2. The ticket is euro 74. Maybe half price if bought earlier from internet.
3. Go down to take first train at terminal 2. Train S8. You can take S1 too but very slow to arrive in HaupBanHof. Indicated in the itinerary will be S8.
4. Stop at Munich Central Train (Munchen HBF)
5. Go up and go terminal 13. Look at the itinerary for train number.
6. Take train until Salzburg HBF (or straight to Villach HBF)
7. If Salzburg, change to terminal 9. Then take to Villach HBF. Just refer to itinerary. So it's a must to print itinerary.

Turkish airline review

I have been hearing a lot bad comment about Turkish airline. So recently I go take Turkish Airline and it's actually pretty good. Well at least better than British Airlines.

Pro
Cheaper than competitor
Big LCD screen
Lots of movie compared to One World Alliance
Look professional with some one dressing as chef
Service is friendly

Con
Not One World Alliance so cannot get miles.

Sunday, March 13, 2016

Aeroline bus service in 2016

Aeroline have been operating between shopping mall Penang and KL many years ago. Specifically between Quuensbay Mall and Sunway Pyramid. It tries to imitate airline services with food and movies. When it started, the price is RM60. After so many years, it still keep the price at RM60 which is good. Normal bus services between KL-Penang is RM35. So it is doubled for Aeroline.

Why do I pay extra RM25:-
a) food, coffee, milo, mineral water
b) movies (fullsize headphones are given)
c) power point to charge your phone or laptop
d) toilet in the bus
e) direct to Sunway Pyramid which is my destination

Sunday, February 28, 2016

Car servicing price

Since almost everyone have a car, the servicing can take a toll on someone's budget. Especially if the servicing is not done at correct interval, your mistake will lead to a major repair.

Anyhow, finding a service center is a challenge. Not all charge the same price.

Here is the pricing that I recently did my Proton Iswara car servicing in February, 2016:-

a)timing belt = RM380 (include timing belt, accessory belt, aircond belt and power steering belt)
b)14" tyre = RM145 (per piece - this consider a bit better than lower end). You can get almost RM125 per piece for the lowest end
c)absorber = RM25 per side on the front, RM15 per side on the back (only the labor. I brought my own absorber, The differences could amount to RM100 or more if you're doing all 4 absorber)
d)lower arm = RM90 per side

All include GST.

The shop I went is Silverstone Tyre.


Thursday, January 8, 2015

Experience buying Imported Motherboard from Junmax Through Lazada

Although I've been a long time customer of Lazada, but this is the first time I bought something from a shop in Lazada that is located in Hong Kong. Since its from Hong Kong, I think it'll take a longer time to reach Malaysia. But it seems the time it takes is pretty quick.

I actually order the motherboard Biostar A8N-5000 for my HTPC on 4th January 2015.

I email Lazada on 6th January 2015 because it takes time to update the status. Here is their response:-

Then the next day (7th January 2015), I got a tracking number:-
And behold, its already in Kuala Lumpur. It actually use Toll Global Express which I never heard of.

I assume I will get this motherboard on Friday. But behold, I got this a day earlier (8th January 2015). That is like 4 days from the time I paid for this motherboard, it delivered to me around 4 days from Hong Kong to Malaysia.

Packaging is awesome. Double pack with a lot of filler.

I would rate this experience as 5/5 star. Now starting to build HTPC. Windows 8 XBMC or XBMCLinux. Erm...


Friday, May 16, 2014

Will Penang Island lose its last A&W outlet?

I'm not sure why Island Penangites don't like A&W. The last A&W in Penang Island is located in Gurney Plaza new wing. At first I thought it was closed for renovation in 2013. But actually it was closed down. Now left one outlet open in Seberang Jaya (I look up at A&W website). This is actually inside a Jusco shopping mall but Jusco is shift to Alma. So the question is, with Jusco leaving this shopping mall, will A&W shift to Alma or A&W will close its last outlet in Penang?

And back to the question. Why Penangites don't like A&W?


Wednesday, April 17, 2013

Gold Price crash

Gold  price crash since 11 April 2013 is long overdue. Although many people think gold price should keep going up, I say everything go up greatly must come down badly.

So is this the lowest point of gold from now onwards? I would say, its time to keep some if money is not a problem.

Its weird that 2 weeks ago, Habib Jewel in Queensbay call me to give me promotional price of RM160 per gram of gold (normal price is upwards of RM190). The question is, does Habib Jewel know something we don't? Conspiracy theorist? Well some said the gold market is rigged ( http://blogs.telegraph.co.uk/finance/thomaspascoe/100024081/the-gold-price-crash-is-further-evidence-of-market-rigging/ )

Final words
Keep some gold if you're doomsday preppers.

Review : Spotify in Malaysia

I used to read about Spotify service in USA and finally the service has started in Malaysia. I'm very excited and downloaded into my Asus Padfone, iPhone and also my Windows PC.

Windows PC - www.spotify.com

Android - https://play.google.com/store/apps/details?id=com.spotify.mobile.android.ui&hl=en

iPhone - https://itunes.apple.com/us/app/spotify/id324684580?mt=8

Review

At first, I thought all the songs will be available. I searched Jacky Cheung and most of its album is there. Awesome. Then I search for the current song like "Shine Your Way" from Owl City & Yuna. And its there. Great. Most of the albums for popular artist such as Jay Chou is available for streaming and download.

But when I search for Aaron Kwok, only 3 albums available. And if I search for Christina Perri (singer of A Thousand Years for Twilight Saga : Breaking Dawn), no songs available. I went to google the string "spotify Christina Perri" and I saw a few songs there. When I click the songs, Spotify software told me that the songs is not available in Malaysia.

A search for Malaysian artists such as Ziana Zain, Sheila Majid, Najwa Latif, Jaclyn Victor, Alif Satar etc does not disappoint (but not all album is available).

So I guess, Spotify still have license problem with certain songs for Malaysian. Its like what happened to iTunes Malaysia when it first arrived in Malaysia. Nowaday, iTunes have more and more songs (probably they have negotiated with the original licensee of the songs).

There's offline mode where you can download maximum 3333 songs and play it without connection to internet. But you need to online at least once a month to verify you're premium user. In the Windows PC Spotify software, there's a slide switch called "Available Offline". When I switch it to green, the song starts to download.

Update for Spotify Windows PC:-Search function will search your PC music library also.

Final words
Great to finally have Spotify. I think the Malaysia songs database will grow bigger in the future. Don't be disappointed if your favorite song is not there. (but mostly should be there).

Price 
Mobile phone listening
For first 48 hours - free premium account
For the next 30 days - free premium account if you enter your credit/debit card information
Thereafter - RM14.90 per month

Windows PC/MAC listening
Free for life - normal account with lower bitrate streaming

Rating
3.5/5