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.