http://www.instructables.com/id/Pong-with-8×8-Led-Matrix-on-Arduino/
http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix
#include “TimerOne.h”
#define PIN_LEFT 18
#define PIN_RIGHT 19
unsigned int left = 0;
unsigned int right = 0;
int angle = 0;
int radians;
byte cols[8] = {13, 3, 4, 10, 6, 11, 15, 16};
byte rows[8] = {9, 14, 8, 12, 1, 7, 2, 5};
byte pins[16] = {5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};
byte screen[8] = {0, 0, 0, 0, 0, 0, 0, 0};
volatile byte screenRow = 0;
volatile byte screenCol = 0;
int _angle;
int _px;
int _py;
int _w = 7;
int _h = 7;
int _wall[] = {3, 3};
int _count = 0;
int _speed = 3;
int _countPoints = 0;
void setup() {
Timer1.initialize(100);
for (int i = 2; i <= 17; i++)
pinMode(i, OUTPUT);
Timer1.attachInterrupt(doubleBuffer);
Serial.begin(9600);
face();
reset();
}
void doubleBuffer() {
digitalWrite(translatePin(rows[screenRow]), HIGH);
digitalWrite(translatePin(cols[screenCol]), LOW);
screenCol++;
if (screenCol >= 8) {
screenCol = 0;
screenRow++;
if (screenRow >= 8) {
screenRow = 0;
}
}
if((screen[screenRow]
>> screenCol) & B1 == B1) {
digitalWrite(translatePin(rows[screenRow]), LOW);
digitalWrite(translatePin(cols[screenCol]), HIGH);
} else {
digitalWrite(translatePin(rows[screenRow]), HIGH);
digitalWrite(translatePin(cols[screenCol]), LOW);
}
}
byte translatePin(byte original) {
return pins[original - 1];
}
void allOFF() {
for (int i = 0; i < 8; i++)
screen[i] = 0;
}
void on(byte row, byte column) {
screen[column-1] |= (B1 << (row – 1));
}
void off(byte row, byte column) {
screen[column-1] &= ~(B1 << (row – 1));
}
void calcWall()
{
left = analogRead(PIN_LEFT);
right = analogRead(PIN_RIGHT);
left = constrain(map(left, 223, 800, 0, 6), 0, 6);
right = constrain(map(right, 223, 800, 6, 0), 0, 6);
clearWall();
on(1, left + 1);
on(1, left + 2);
on(8, right + 1);
on(8, right + 2);
_wall[0] = left;
_wall[1] = right;
show();
}
void clearWall()
{
for (int i = 0; i < 8; i++)
screen[i] &= B01111110;
}
void clearGame()
{
for (int i = 0; i < 8; i++)
screen[i] &= B10000001;
}
void loop() {
calcWall();
enterFrameHandler();
delay(50);
}
void enterFrameHandler()
{
if (_count++ < _speed)
return;
_count = 0;
checkCollision();
calcAngleIncrement();
show();
}
void retorted(int angle)
{
Serial.println(angle);
_angle = angle;
if (++_countPoints % 5 == 0
&& _speed > 1)
_speed–;
}
void resetAnim()
{
for (int i = 0; i < 8; i++)
{
screen[i] = B11111111;
delay(25);
}
for (int i = 0; i < 8; i++)
{
screen[i] = B00000000;
delay(25);
}
}
void face()
{
on(1, 1);
on(1, 2);
on(2, 1);
on(2, 2);
on(7, 1);
on(7, 2);
on(8, 1);
on(8, 2);
on(1, 1);
on(1, 2);
on(4, 4);
on(4, 5);
on(5, 4);
on(5, 5);
on(2, 7);
on(7, 7);
on(3, 8);
on(4, 8);
on(5, 8);
on(6, 8);
delay(5000);
}
void reset()
{
resetAnim();
_px = random(3, 5);
_py = random(3, 5);
_angle = random(0, 2) == 0 ? 0 : 180;
_speed = 5;
_countPoints = 0;
show();
delay(500);
}
void show()
{
clearGame();
on(_px + 1, _py + 1);
}
void checkCollision()
{
if (_px == _w – 1)
{
if (_angle == 315 || _angle == 0 || _angle == 45)
{
if (_py == _wall[1] || _py == _wall[1] + 1)
{
if (_angle == 0 && _py == _wall[1])
retorted(225);
else if (_angle == 0 && _py == _wall[1] + 1)
retorted(135);
else if (_angle == 45 && _py == _wall[1])
retorted(135);
else if (_angle == 45 && _py == _wall[1] + 1)
retorted(180);
else if (_angle == 315 && _py == _wall[1])
retorted(180);
else if (_angle == 315 && _py == _wall[1] + 1)
retorted(225);
}
}
}
else if (_px == 1)
{
if (_angle == 225 || _angle == 180 || _angle == 135)
{
if (_py == _wall[0] || _py == _wall[0] + 1)
{
if (_angle == 180 && _py == _wall[0])
retorted(315);
else if (_angle == 180 && _py == _wall[0] + 1)
retorted(45);
else if (_angle == 135 && _py == _wall[0])
retorted(45);
else if (_angle == 135 && _py == _wall[0] + 1)
retorted(0);
else if (_angle == 225 && _py == _wall[0])
retorted(0);
else if (_angle == 225 && _py == _wall[0] + 1)
retorted(315);
}
}
}
if (_px == _w)
{
reset();
}
else if (_px == 0)
{
reset();
}
else if (_py == _h)
{
if (_angle == 45)
_angle = 315;
else if (_angle == 135)
_angle = 225;
}
else if (_py == 0)
{
if (_angle == 225)
_angle = 135;
else if (_angle == 315)
_angle = 45;
}
}
void calcAngleIncrement()
{
if (_angle == 0 || _angle == 360)
{
_px += 1;
}
else if (_angle == 45)
{
_px += 1;
_py += 1;
}
else if (_angle == 135)
{
_px -= 1;
_py += 1;
}
else if (_angle == 180)
{
_px -= 1;
}
else if (_angle == 225)
{
_px -= 1;
_py -= 1;
}
else if (_angle == 315)
{
_px += 1;
_py -= 1;
}
}
Posted in Output
Devices Leave a comment
Edit
Output Device – example : LED array
Posted
in Embedded
Programming, Output
Devices Leave
a comment Edit
Interface and Application Programming
/**
* Simple Read – Combined with Neil Gershenfeld’s hello.light.45.py
* http://academy.cba.mit.edu/classes/input_devices/light/hello.light.45.py
* adjusted values pulled from Neil’s python visualazition program to make sense
of high and low readings.
*
* Read data from the serial port and change the smiley face.
* when the phototransistor connected to the hello light board is receiving
* varing levels of light.
*/
import processing.serial.*;
Serial myPort;// Create
object from Serial class
int val; // Data received from the serial port
int sensorData; // Data recieved from the serial port with 1,2,3,4 framing
numbers filtered out
int highVal; //high value read in from Neil’s C code
int lowVal; //low value read in from Neil’s C code
int actualVal; // adjusted sensor value
PImage a; // Declare variable “a” of type PImage
PImage b;
PImage c;
void setup()
{
size(52, 52);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you’re using.
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
a = loadImage(“0.gif”); //
Load the image into the program
b = loadImage(“2.gif”);
c = loadImage(“1.gif”);
}
void draw()
{
if (myPort.available() > 0) { // If data is available
val = myPort.read(); // read it and store it in val
if (val > 4) { // Filter out the framing numbers: 1,2,3,4
highVal = myPort.read(); // read the high value sent from sensor and store it
lowVal = myPort.read(); // read low value from sensor it and store it
actualVal = 256 * (highVal + lowVal); // getting the actual value of the sensor
println(“The actualVal is ” + actualVal); //print to the screen
}
//EXPERIMENT WITH THE VISUALIZATION BELOW
background(255); // Set background to white
//READ VALUE BEING PRINTED IN
//ADJUST THE VALUE AFTER THE <
//If you are not getting changes in the visualization in response to changes in
the sensor
if (actualVal < 300) { // If the sensor value is less than a this number
image(a, 0, 0);
}
else if (actualVal > 1000) {
image(b, 0, 0);
}
else { // otherwise….
image(c, 0, 0);
}
rect(50, 50, 100, 100);
}
}
Tutorial : Using Cygwin and Mercurial in Windows with
WordPress static HTML (for dummies)
To make mercurial working in
Windows environment, you have to check few things while you’re installing
Cygwin.
Find
an article named Python in ‘Select Packages’ menu and click on circulating
arrows marked in the picture above.
You
can just type ‘python’ in the search window but NEVER PRESS
ENTER AFTER TYPING IT!
Pressing
enter makes installation to continue before any change is made.
Then type ssh and click
again. SSH(Secure Shell) is to encrypt data communication between two networked
computers.
The installation takes about
20 minutes depending on the line speed.
In Barcelona, we decided use
WordPress blog to create students’ page. To do this, you need to install
a plug-in called ’WP Static HTML Output’, which generates exact
copies of every file of your word press page on your hard drive.
It is important to write the
correct web address in the Base Url.
In my case, It is
‘http://academy.cba.mit.edu/2012/students/koh.hunmin/’
NOTE:
Adding ‘/’ at the end of the address is crucial to have right copies when you
upload it on MIT server. Many people had troubles in uploading their page
because of this.
Click ‘Generate’ and
download.
Mercurial
uploading Mantra
Open Cygwin, go to the
directory which you want to upload in your hard drive (working directory).
Then type hg pull. It’s
going to take a while.
1.hg pull
To
download changed files from the server.
2.hg update
To synchronize
the archive in your hard drive with the latest version you just downloaded with
hg pull.
3.Copy your static HTML files to your
folder in your hard drive. Overwrite everything.
Red
circles mean that there’s discordance between… I don’t know. I’ll tell you
later.
Anyway
it’s not good.
not happy :(
4.hg add
To add
new files for pushing. Otherwise images on your webpage won’t appear when
uploaded
5.hg commit -m “message”
To
make a log for your upload and apply , I usually type <hg commit
-m ”hk”>. hk for Hunmin Koh.
Now it’s happy :)
6.hg push
To
upload changes you made on the server.
Now we
have an exact copy of wordpress blog in the archive.
IMPORTANT
:
1. If someone’s trying to
upload at the same time with you, Mercurial will ask you whether you want to
force your uploading. NEVER DO THIS unless you want to
receive an angry email from Neil Gershenfeld. Doing this will create multiple
heads in the archive thus make it dirty.
If you get this message, wait
a little bit and try again from <hg pull>.
2. It’s better not to delete
any files/folders in your working directory without using Cygwin. If you delete
something, the Mercurial will find out when you type <hg update> and ask
whether you want to ‘merge’ your version.
then you can type <hg
merge> but It was a little bit tricky as far as I remember.
I’ll update this post as soon
as I get more precise knowledge.
Posted in Project
Management Leave a comment Edit
On the 3rd week we
learned about Computer Aided Design(CAD), the very basis of every fabrication
process in Fab Lab.
Neil introduced variety
of free design tools. And I was busy with downloading and installing the
software
The assignment was to
create a 3D model of each one’s final project.
After the lecture,
everybody had time to discuss what they were thinking for the final project.
Actually I thought of something for the final project in Korea, but I wasn’t
sure at the moment whether it’s a good idea to make something like that
for my final project in Fab Academy. Because it was
a
I won’t try to explain why
this came up to my mind. But I was pretty sure that this could be electronics,
embedded programming, 3D printing, networking and
communications.
But there was one big problem
remained in my mind. This is like a debut stage for my career in the Fab Lab
Network and I might be referred as ‘The dildo guy’ forever.
But luckily, a better
idea came across my mind when I was staring the world map on the wall of
Fab Lab. While attending Fab Academy’s global video lecture in Fab Lab
BCN, I noticed a laser-cut world map on the wall with Fab Lab sites all over
the world.
When I was in Sri Lanka, My
parents used to call me 3 in the morning around just to check whether I’m
okay. Same thing is happening these days after I came to Barcelona.
There are numerous ways to check time difference when you are going to
make international calls, but maybe those thing do not apply to my parents…
Anastasha,
Luciano, Jesus.
Anna
is a sociologist Fab City Project.
After
the meeting called me out for a talk. I was 25% scholarship but
didn’t dare to ask
The
offer was two things, first, Do a introductory tutorial about Solidworks on
Friday
It is
going to be a good chance to
Yeah! I’m going to be famous!
(By
the way, there is a dance studio named ‘Fab Acadmy’ in Tokyo and the logo above
is from their website. I think there might be a confusion someday.)
my
former lecture materials from Sri Lanka.
Luciano suggested me to have
a video tutorial
There was delay between my
computer and
http://hunmin.fablabbcn.org/solidworks-tutorialrugby-ball/
On Tuesday, I received and
email from Roberto in Lima saying that my tutorial was very useful for him.
Thanks Roberto! Your comment made me so happy that day :)
To be continued…
Posted in FABulous
Leave a
comment Edit
¡Hola a todos!
For the rest of the first week,
pretty much nothing happened. I dropped by to the lab few times to check
what’s going on but pretty much nothing was going on either. So instead I
signed up for a Spanish class and went house hunting. Finally I found a loft
two blocks away from the school.
Home sweet home.
So once again it was
Wednesday. Luckily nothing was happened to Neil so we could have him on the
video today. Today’s lecture was about project management.
Especially about a software called Mercurial.
”Mercurial is a
cross-platform, distributed revision control tool for software developers. It
is mainly implemented using the Python programming language, but includes a
binary diff implementation written in C. It is supported on Windows and
Unix-like systems, such as FreeBSD, Mac OS X and Linux. Mercurial is primarily
a command line program but graphical user interface extensions are available.
All of Mercurial’s operations are invoked as arguments to its driver program
hg, a reference to the chemical symbol of the element mercury.” Says Wikipedia.
What I’ve understood so
far is this. There is a server in MIT Center for Bits and Atoms where all the
students upload their weekly progress. But in case of server failure or a
problem in internet connection, we could lost all the data or are unable to
check the previous progress. So the idea is make back up data in every
participants’ hard disk drive every time they upload something.
But at the moment, it
seemed quiet irrelevant to what we are supposed to learn in Fab Academy.
Honestly, I didn’t pay much attention. And I couldn’t imagine the consequence
that was about to happen to me…
From the left Rodrigo, Tomas, Santi,
Blanca, Heloisa, Tomas (director), Nerea
After the lecture, everybody
briefly introduced oneself again. Total 9 people is participating in Barcelona
this year.
To run Mercurial in Windows,
you first need to install Cygwin. Cygwin is a Unix-like environment and
command-line interface for Microsoft Windows(thank you again Wikipedia). I felt
already smart to install something with commend line, so I even posted
something like this on my Facebook.
In Barcelona, we decided use
WordPress blog to create student’s page. To do this, you need to install
a plug-in called ’WP Static HTML Output’, which generates exact
copies of every file in your word press page on your hard drive.
I touched html scripts a
little bit to change frame size and add some links and widgets. And Tomas
helped me a lot with Mercurial, but I still couldn’t totally understand how
Mercurial works.
The next Tuesday Anna sent an
email saying all the students have to change their directories in
archive. I wanted to prove myself that I can do it by myself. So I
tried.
Me try Mercurial. Me try in me room. Me
no happy.
But it didn’t work. Error
messages saying ‘something is colliding’ kept appeared. Mercurial asked
me whether I want to force upload. As a big fan of Star Wars, I said yes. But
it didn’t work. So I forced again. Again. Again. Again. And gave up.
Then I got a new mail from
Neil.
…
It was so embarrassing.
In fact, after being so
motivated by his book, I tried to send emails to Neil several times. I still
have 2 unsent emails in my mail box. And this is my first encounter with Neil
after all those years? Oh come on…
Moreover, that morning I
discovered I payed nearly 600 euros for commission when I exchanged
traveler’s check to pay my rent. I felt like I was
the dumbest person in the world.
Tutorial : Using Cygwin and Mercurial in Windows with WordPress static HTML
(for dummies)
Here is more detailed description of
what possibly caused the problem that night.
On the next day, I felt much
better. ‘Nobody got hurt, data restored. It’s just a natural process of
learning and nobody got hurt so no big problem. At least now everybody
got familiar with my Asian name(It takes time to memorize).’ And I headed
to the lab imagining people’s reactions.
“Hey! I saw your name on the
email last night!”
“Yeah… haha… I’m the most
famous student for now.”
This time each student had 1
minute to introduce oneself. I was quiet relieved when I heard someone saying
“Sorry for messing up with the server last night” over the
video. Apparently I wasn’t the only person.
Now It was my turn and I
started with the same thing. “I also want to apologize for what happened last
night…”
Then Neil interrupted.
“You don’t have to apologize. Just learn.”
Yeap, right. That’s why we
are all here for.
To be
continued…
Posted in FABulous
Leave
a comment Edit