Showing posts with label 4. Show all posts
Showing posts with label 4. Show all posts

Wednesday, January 29, 2014

Musing Journal #4


Plan, Do, Learn

For the longest time, I always work with Learn, Plan, Do. This is because I value my time and by properly learning the materials, I am able to properly plan the activity, so that when it comes to actually doing it, I will have no trouble at all.

This has served me well throughout the years, whether it's engaging in a project, or writing term papers, the proper outline has been essential in getting things done quickly.

Lately, though, I have a second thought about the process. Probably because I'm being overwhelmed right now. There's so much to do that if I have to fully learn everything, then a lot of things won't get done quickly. I suppose there's a good side about "do one thing at a time" philosophy, however, I wonder if that's a good thing when there's so much to do at one time. In essence, I wonder if there's a faster way to do things than one at a time.

So, I have been doing things around. Instead of Learn-Plan-Do cycle, I decided on Plan-Do-Learn cycle. Make plan, Do plan, and Adjust accordingly. So far, it has been working well. Things are getting done, and more importantly, I am able to manage various projects at once. I still limit myself to doing two or three big things per day. And I focus on the most important thing to do in that day. But as weeks go by, I am able to see improvements in all aspects of my life.

If you look at my blog, you see various things going on. That's because I have wide ranging interest, and the fact that had I focus on one thing at a time, there will be some holes on it. So, I have no choice. I have to spread my activities around, regardless how I feel about it.

And that's a good thing. The ability to learn from doing does have value. I keep changing things and well, I see definite improvements in each separate activities. Mind you, I'm still overwhelmed. However, I manage things much better now. I am now able to see progress on my schedule.

So, all I have to do now is keep improving, and I will catch up with the rest of the schedule eventually. It takes longer than expected, but steady progress is better than heroic actions, especially since I have a tendency to burn out after such heroic actions.

Thursday, October 3, 2013

Book Review #4


Raspberry Pi for Beginner bookazine

This magazine-as-a-book is part of LinuxUser&Developer bookazine series. Just like a magazine, it is filled with large glossy color, and features easy to read passages. The problem with the format is that there are lots of different articles exploring different ideas, but limited in length. So, it's much of an exploration of ideas, as opposed to books that dwell in implementation details. The closest thing I can think of is O'Reilly Getting Started series, except it's light on resources, and plenty of photos. With that in mind, I still enjoyed the bookazine tremendously.

It starts with the basics, what is Pi, what do you do with it, and so one. It seems like every book about Pi deals with it. Considering the volume, though, it's clear that this bookazine is intended for extreme novice. For that, I think this is a good first Raspberry Pi book. My interest lies in the middle section: Projects. It's here that I find articles about remote control car, solar powered pi, webcam server, and so on. Unfortunately, these are light on details. Which means two things:

  1. The issues explored are necessarily brief, focusing only on core features and functions.
  2. The problem solving, in case something goes wrong, is non-existent.


To be fair, point#2 is also light in other works, including technical books. But with longer text, I can usually research such troubles on the Internet. I'm having trouble picking up keywords to research the problem further. In the end, if the project is successfully modified, it is because I spent hours, if not days, researching the subject matter. I don't think that's a good book implementation. But it's certainly acceptable for magazine implementation.

In other words, is this bookazine format successful? If you think of it as fountain of knowledge, then no. If you look at it as fountain of ideas, then it succeeds admirably. So, if you're a new Raspberry Pi user or someone who's interested in knowing what Raspberry Pi is all about, then this bookazine is a good first Raspberry Pi book to start.

Sunday, September 15, 2013

Cooking Journal #4

Safron Rice with Oyster

There are all kinds of rice. Sometimes, I go with fried rice. Or maybe brown rice. Or the easy kind, because the package is sold in supermarkets, Saffron rice. It used to be saffron is sold is small spice package. The one I use is already mixed, so it's extremely easy to use.


  1. Add yellow rice package into the pan (1 cup)
  2. Add Oyster package into the pan
  3. Add 1.3 cup of water into the pan
  4. Hit "White Rice" to start



Rice to pan

Oyster to pan

Water to pan

Hit Start

Sunday, August 11, 2013

Raspberry Pi Journal #4

Video Playback Trouble
OMXPlayer Trouble. MPlayer2 works fine.

So, I was connecting my USB flash drive to Raspberry Pi, and I played some videos I have that I recorded using my Windows 8 camera. The resolution is HD. Omxplayer plays fine as usual, but somehow, there's no sound! That's strange. I looked at the boot configuration, it says hdmi_force=2, which means HDMI output. Furthermore, I believe that I did play the video with sound before.

Putting in -o hdmi didn't work, believe it or not. I was very disappointed. So I tried various options. This works:

omxplayer -r -o hdmi filename

I was so very happy, until it reaches the end of the video, and the whole screen went blank! Uh-oh. Not good. So very not good!

I wasted several hours trying to debug the process. In the end, though, I gave up. It's nice to be able to use hardware decoding, but if in the end I have to shutdown the computer and reboot, then that's not the way I'm going to do it! Maybe there is a command that I can use to reset the display. If so, then I can simply write a script just to make sure the command to reset the display is run after omxplayer finished playing. I don't know such command.

Obviously, I'm not going to use that program ever again.

So, I went to the package directory. I did a search and found mplayer2. Looks good. The package seems to be rather well-developed. So it's pretty simple to just download the whole package.

sudo apt-get install mplayer2

Curiously, when I did a which mplayer2, I came up blank. So, I did which mplayer. Bingo! There it is! Obviously, there'd be a conflict if I ever install mplayer, instead of mplayer2. Will have to be careful in the future.

Then I ran some test videos.

  • Nintendo 3DS video: Ran fine, no problem.
  • Flip Videos: Ran fine, no problem. Can do Full Screen. 50% CPU
  • WIndows 8: Ran slow. Out of sync. 100% CPU

None of the videos ran smooth, BTW. I had to use -framedrop option to run it. I was extremely disappointed that the Windows videos can't be shown. I'll have to make sure to record in low resolution mode from now on. Or, I can simply use my Nintendo 3DS to record the video. It ran just fine!

Here's the screen capture of the video in action:

Not bad for a windowed application that does not take over the whole screen. Unlike omxplayer, I may add. So, I'm happy for now.


EDIT:
Finally figured out the command to refresh the screen. There is a couple seconds delay at the end, but at least I get my screen back! I ended up making a script called "omxplay", do a chmod 755 and put it in /bin

#!/bin/bash
omxplay -o hdmi -r "$1"
fbset -depth 8 && fbset -depth 16




Tuesday, August 6, 2013

Petit Computer Journal #4

Input + Math Tutorial


Knowing that computer is composed of numbers makes it easy to understand. That does not make it easy to do, you see, just to understand. The point is: The computer does what you tell it to do, not what you think you tell the computer to do. Faulty language implementation is an exception to that rule, and even then, you need to figure out a way around the problem.

Computer programming can be fun, but it can be very frustrating, indeed. The question is, what will you do to make computer programming fun? If the answer is to make games, then you're probably off to the wrong start. If the answer is to make games that people want to play, then you're probably off to the right start.

You see, computer programming is all about problem solving. What problem are you trying to solve? Without a clear goal, you probably will just do things randomly. Maybe you discover something, or maybe not. With a clear goal, however, you can work on the steps to achieving that goal. Then, when you finally solve that problem and arrive at your goal, your satisfaction level is quite high. That, my friend, is the fun of computer programming.

It's like winning a game, solving a puzzle, guessing a riddle. Before you did it, you don't know. After you did it, you know. That's fun.

Speaking of goals, you are still a beginner, so let's keep things simple for now. Let's start by figuring out how to tell a computer to do something simple.

Inkey$, input, linput

Let's get the keyboard input out of the way real quick. What is the difference between INKEY$, INPUT, and LINPUT? Write a small program to check it out!

'Keyboard input source code example
@MAINLOOP
VSYNC 1: A$=INKEY$
IF A$!="" THEN B$=A$
LOCATE 0,0:?"A$=";A$;"   "
LOCATE 0,2:?"B$=";B$;"   "
GOTO @MAINLOOP

There are 3 things you have to see here:
VSYNC 1: This synchronized the system 1/60 second. Try it with different values and see what happens!
A$=INKEY$: This gets the keyboard value and assign it to A$
IF A$!="" THEN B$=A$: Since the value disappear at the next iteration, and we want to keep the old value, we assign the value of A$ to B$, but only if there is something to copy.

And that's it! If you are writing a computer game that cannot wait for user input, then INKEY$ is the way to go. I understand that it isn't the easiest to use, but it's there if you want it.

What's the difference between INPUT and LINPUT? Try them out and see!

@MAINLOOP
VSYNC 1: INPUT "X,Y",X,Y
?"X=";X:?"Y=";Y
?:?:'DOUBLE BLANK LINES
VSYNC 1: LINPUT "DATA:";A$
?"A$=";A$
WAIT 300
GOTO @MAINLOOP

INPUT takes several inputs and assign them to different variables. This is very useful for inputting numeric values. Just type them out and separate them with comma. LINPUT takes in a string, commas included. Just one string.

Can you take string and numbers using INPUT? Try it and see!

@MAINLOOP
VSYNC 1: INPUT "X$,Y",X$,Y  '<==change here
?"X=";X$:?"Y=";Y            '<==Change here
?:?:'DOUBLE BLANK LINES
VSYNC 1: LINPUT "DATA:";A$
?"A$=";A$
WAIT 300
GOTO @MAINLOOP

Yes, you can! If the program doesn't understand your input, it will ask you to re-enter the data "?Redo from start". In which case, you re-enter the data, hopefully without mistake this time!


Touch Screen TCHX,TCHY,TCHST,TCHTIME PNLTYPE


Buttons and keyboard are nice, but we have something there that is just begging to be used: Touchscreen! I know I'm bucking the convention here, since most people are satisfied writing their beginner's program using INPUT or BUTTON(), but I really want to use the touch screen. Fortunately, it's as easy to use as INKEY$.

It's just some variables, and you even use it like you do INKEY$. The difference is that there is more than one, and you use numeric variables. Let's do it. It is helpful if we disable the on-screen keyboard. We do it via PNLTYPE command. Simply set it to "OFF".

'Touchscreen input source code example
PNLTYPE "OFF"
CLS
@MAINLOOP
VSYNC 1
X=TCHX:Y=TCHY:S=TCHST:T=TCHTIME
LOCATE 0,0:?"X=";X;"   "
LOCATE 0,2:?"Y=";Y;"   "
LOCATE 0,4:?"S=";S;"   "
LOCATE 0,6:?"T=";T;"   "
GOTO @MAINLOOP

Hit the Select button to stop the program. Yup. Just like INKEY$. The difference is, X and Y values are not reset to zero when the stylus is off the screen even though the status (TCHST) and timer (TCHTIME) are reset.


Math - Arithmetic


Alright, I need you to confess: Who among you have not yet finished 1st Grade? You know, the school grade right after Kindergarten? Whaat? You don't know Arithmetic? Oh, dear. This is bad. I think maybe you need to learn how before we can continue.

Haha, joking aside, you do need to know Arithmetic. Some Trigonometry, too. How about Algebra? Yes, you do need to know how to manipulate variables. Fortunately, if you know Show-and-Tell, you may be alright. Here's a little something that's useful to know: Mapping function.

map() is something that is built-in in Processing computer programming language. It's a good programming language. Check out www.processing.org for details.

In the meantime, let's implement it in BASIC. The idea is, if you have a number that is between two numbers, given another two numbers, what will be the number that has the same ratio as the first? In mathematical format, assuming X is the first number, and Y is the second, we have

X1-X2-X3 X2 is between X1 & X3
Y1-Y2-Y3 Y2 is between Y1 & Y3
Since the ratio is the same, we have
(X2-X1)/(X3-X1)=(Y2-Y1)/(Y3-Y1)

Solve for Y2:
(Y2-Y1)/(Y3-Y1)=(X2-X1)/(X3-X1)
(Y2-Y1)=((X2-X1)/(X3-X1))*/(Y3-Y1)
Y2=(((X2-X1)/(X3-X1))*/(Y3-Y1))+Y1

And that's all there is to it! Work it out on paper if you're having trouble. I find it helpful to draw triangles to visualize the problem.


A Math Explorer sample program


We want to feature a lot of math here, so we're going to just do it all in one program. The program will features different modes, and take inputs from touch screen, normalized to 0-5 for both X and Y. Furthermore, if the stylus is on top-left corner, we'll change the mode.

0: Simple Arithmetic
1: Math functions
2: Logical Math
3: Exponent

Here goes:

Part 1: Touch screen input. No problem there. Just copy it from the sample program above.


'Math Explorer
PNLTYPE "OFF"
CLS
@MAINLOOP
VSYNC 1
X=TCHX:Y=TCHY:S=TCHST:T=TCHTIME

Part 2: Display X,Y, Mode, and Cycle Mode. If you remember our COUNTER program example? Yup, just like that!

IF (X<32 AND Y<24 AND T==1) THEN MODE=MODE+1
MODE=MODE%4:'MODE=0-3
LOCATE 0,0
?"X=";X;"     Y=";Y;"     MODE=";MODE


Part 3: Normalize X and Y. We already have the mathematical formula for this. Just implement that using GOSUB.

X1=0:X2=X:X3=255:Y1=0:Y3=5:GOSUB @MAP:XP=Y2:'CALCULATES XP=Y2
X1=0:X2=Y:X3=191:Y1=0:Y3=5:GOSUB @MAP:YP=Y2:'CALCULATES YP=Y2
?"XP=";XP;"     YP=";YP;"     "

GOTO @MAINLOOP

@MAP
Y2=(((X2-X1)/(X3-X1))*(Y3-Y1))+Y1
RETURN


And that's the beginning. We'll continue with Part 4 next, but first, run this program and see that we have normalized XP and YP, and that the MODE cycles 0-3 satisfactorily.



Change the program slightly to this before continuing. Yes, I expect you to be able to read! I know it's hard in the beginning, but please persevere.

'Math Explorer
PNLTYPE "OFF"
CLS
@MAINLOOP
VSYNC 1:IF MODE!=2 THEN CLS
X=TCHX:Y=TCHY:S=TCHST:T=TCHTIME

IF (X<32 AND Y<24 AND T==1) THEN MODE=MODE+1
MODE=MODE%4:'MODE=0-3
LOCATE 0,0
?"X=";X;"     Y=";Y;"     MODE=";MODE;"     "

X1=0:X2=X:X3=255:Y1=0:Y3=5:GOSUB @MAP:XP=Y2:'CALCULATES XP=Y2
X1=0:X2=Y:X3=191:Y1=0:Y3=5:GOSUB @MAP:YP=Y2:'CALCULATES YP=Y2
?"XP=";XP;"     YP=";YP;"     "

GOTO @MAINLOOP

@MAP
Y2=(((X2-X1)/(X3-X1))*(Y3-Y1))+Y1
RETURN


And that's the program. Now, here is some snippets of code. I trust that you know where to put this.

?:?
ON MODE GOTO @ARIT, @FUNC,@LOGI, @EXPO
GOTO @MAINLOOP:'INVALID CHOICE

@ARIT
?"X+Y=";(X+Y)
?"X-Y=";(X-Y)
?"X*Y=";(X*Y)
IF Y!=0 THEN ?"X/Y=";(X/Y)
IF Y!=0 THEN ?"X%Y=";(X%Y)
IF YP!=0 THEN ?"X%YP=";(X%YP)
GOTO @ENDLOOP

@FUNC
?"FLOOR(XP)=";FLOOR(XP)
?"RND(X)=";RND(X)
?"RND(XP)+20=";RND(XP)+20
?"ABS(X-128)=";ABS(X-128)
?"SGN(X-128)=";SGN(X-128)
?"SWAP  ":SWAP XP,YP
?"XP=";XP;"     YP=";YP
IF S==1 THEN WAIT 30
GOTO @ENDLOOP


@LOGI
LOCATE 0,4
?"X=  ";:V=X:GOSUB @BIN
?"Y=  ";:V=Y:GOSUB @BIN
?"AND ";:V=(X AND Y):GOSUB @BIN
?"OR  ";:V=(X OR Y):GOSUB @BIN
?"XOR ";:V=(X XOR Y):GOSUB @BIN
?
?"X=  ";:V=X:GOSUB @BIN
?"NOT ";:v=NOT(X):GOSUB @BIN
?"!   ";:v=!X:GOSUB @BIN
GOTO @ENDLOOP

@EXPO
?"SQR(X)=";SQR(X)
?"EXP(XP)=";EXP(XP)
IF X!=0 THEN ?"LOG(X)=";LOG(X)
?"POW(2,XP)=";POW(2,XP)
?"POW(3,XP)=";POW(3,XP)


@ENDLOOP
GOTO @MAINLOOP

'SPLIT THIS TO THE END

@BIN
FOR I=0 TO 7
P=POW(2,I)
IF (P AND V) THEN ?"1"; ELSE ?"0";
NEXT
PRINT
RETURN




One more round of Math and we'll be done! It's all about Trigonometry. We'll save it for later until after we learn Graphics!