Friday, November 11, 2011

[arduino] RGB led, Introducing LOLSs

  Introducing LOLSs, an arduino shield made by my student lihsheng using uln2003a darlington.
LOLSs is an acronym, which stands for LED O' LihSheng shield. It uses 3PWM on arduino to control brightness of RGB LEDs. If we use digital output instead of PWM, we could only turn on and off the LED, which is ..... BORING. Supply is 12V, can support about 6RGB LEDS (that is 3x8 LEDs in total)
Behold...
 The component side of stripboard is soldered on the connecting copper side instead

Now about RGB LED, in each of them there are 3 LEDs in total which is Red Green and Blue. Red is 2.2v, Blue and Green is 3.5v. Hence we need to use resistors such as 150ohm and 80ohm respectively to limit the current. If not, the LEDs will be burnt. Here, I tested my RGB LED with 1.5v, hence the dim green colour.
 This is how the RGB led strip looks like. We would need a LED driver circuit to power up long stretch of them. LOLSs can drive up to 6RGB LEDs with 12v 800mAH NiCad battery.

There are 4 "legs" from a normal LED, the longer leg is the anode which we connect the +ve side of VCC. The shorter legs are the cathode which we connect -ve or gnd.

Now, how can we wire the LEDs to the arduino?

check out these diagrams by ADAFRUIT

Now, the fun part. Programming the RGB LED. We could do several of the below in code.
1. Light the colour one by one
2. Fade the brightness of the RGB LEDs with PWM. There is example code to fade 1 LED. It is available at Examples->Basics->Fade
3. Mix colour of the RGB LED. the value of RGB LED follow this format [255,255,255]. For each colour, 0 to turn off, 255 to turn on. Any values in between is to change the brightness. If all 3 led is 255, what is the resulting colour=? WHITE 
3. Make the colour change according to music
4.etc etc

Here is my rendition of RGB led with Arduino, based on the sample code given.


code here

Thursday, November 3, 2011

[game] Shogun2 Legandary difficulty playing for Tokugawa clan

I am playing Shogun2 since the last 2 months and you know what, medieval2 last me for a whole 3.1 years! I played all factions and difficulty level. lol


This campaign is VERY challenging. I got wipe out, annihilated, humiliated, sieged at 10:1 and more.
After a few tries for loosing at the 3-4th turn and the last 40game restarts I did not manage to clear the 30th turn mark.

Let me give some background information about shogun2 tokugawa clan at Legendary difficulty level.
I started off as vassal for Imagawa with 2000gold, 2 generals, 1unit of yari samurai, 2units each of yari ashigaru and ashigaru archers. I have a metsuke (secret police, good in maintaing order while taxing the population) too. Being a vassal means my overload gets 50% of my $$ and i can only wage a war which pisses off my boss. Politically, putting me at a very passive position. I will explain more later... less income means I can't afford big/elite armies. The whole objective of the game at the early stage is to shake off the vassal status by either Imagawa declare war on me, which hurts their daimyo reputation and diplomatic score or let other enemy rummage over Imagawa. Based on the art of war of sun-tzu, if I let my friend's enemy attack my "friend" and borders me too early, i am in big trouble. 唇亡齿寒


At the start of the game, Oda clan is my arch nemesis and they are marching on my land. Which means, my income from farm got affected, population unrest is higher=> bad and their army outmatch mine in terms of head count and eliteness!

After many many tries over the weekends playing the game, got wipe out then restarting game, experimenting with the opening strategy to outlast my overload. I think i got one of the effective "opening strategies".

At 1st turn. offer 20 turns or more of military access to neighbour such as saito and kiso for gold. the more the merrier. I got about 4000 gold for 20turns or 6000 gold for infinite turns. Offer to trade with both of the too, this will generate some income. While still a vassal, let other factions that border you pass your land for a fee. This will generate lots of income. Offer to marry Saito's ugly-greedy-evil-bitch daughter at 120gold (hey, i got 4000 from previous remember?). Straight away the relationship became "very friendly". By doing this , Saito will take Oda (hostile with each other) sooner and defuses the enemy marching on my land and later shadow me from the north against Hattori. With the newly acquired gold, i ordered my metsuke to bribe the oda clan's army that is on my land with 35% chance. A successful acquisition would cost me 3670 with 1unit of yari samurai and couple of the ashigaru units. Next, order my daimyo to attack the remaining Oda force to earn some bad-ass reputation (i always groom my generals to be the level of "intimidating", good for maintaining peace on newly acquired land.). Now the enemy retreated, I had a choice of pursuit Oda at Omi (very fertile land) or not. The fact is, with my current army I have a less than 50% chance of winning. Got to give it to Saito. Research on "chi arts", with the focus of getting my kishio ninja ASAP. These are the featured units for Tokugawa clan. Destroy the "rice exchange", so that the sake den could be build at the next turn. Build the farm land+1 upgrade to sustain the clan. Remaining amount of gold, recruit ashigaru archers but bear in mind the upkeep should not exit the next turn income. Hit next turn.

Turn 2-4. Build sake den. Train more arches. Research chi-arts to get my kishio ninja. Build trading port and start to send ships to explore for new commodities. Bear in mind, the army/navy maintain cannot be more than the next turn income.

Turn >4. Upgrade the sake den all the way till criminal syndicate. Behold, my Kishio Ninja. They are expensive tho. 884 for recruiting and 295 for upkeep. By now, Oda should be wipe out by Saito and Hatori is on the rise. Rule of thumb, try to save more gold for rainy days.

Turn 45. Hojo declare war on Imagawa, my overload. By now, i have some gold at about 2k, an army that could defend my castle and several ninja and metsuke. Here comes the intriguing part. I want to hold Izu the gold producing land held by Hojo and it's kinda far away. I want it so badly i would use my ninja to sabotage imagawa's marching army to delay it by 1 turn so that i could take Izu. But the bad thing is, Hattori would border/siege my castle to the west because Saito gave in to early. Eventually Takeda will then border Izu and overwhelm my castle with their elite calvary. Build a temple too, and the monks recruited could be use to cite unrests in rival land. The rebels will eventually overpower the owner and own the land and thus I would attack the rebels. Good way of taking their land without inciting war.

The AI in shogun2 is AWESOME, almost 50+ game restarts with different strategies i experienced different game play and still end up loosing at 70+ turn.

The only time i played until 100+ turn was I did not participate in the war against Hojo and my overload was killed, freeing me from my vassal status. With my monk+mesuke+ninja strategy i took many lands and maintained a chummy relationship with the owner which I took the land from. Awesome isn't it. Things went south when my favourite general Iyeyasu (historically, he created the tokugawa shogunate that runs for 265 years) and the next inline to be daimyo got sandwiched by Hatano, Asai and Kitabake while retreating to the nearest castle. Just a few more inches and he will be safe. Because playing at Legendary difficulty, i could not do a quick save nor a reload, I can't turn back time. Sounds like life huh?? After many set backs i resort to manually copy the save game file to create a "backup" which I found out later.




If you are interested to pick up from where I left with, here is the game saved at turn 45.
http://db.tt/5JD5ZfvS
paste it in the saves_game folder at C:\Users\"username"\AppData\Roaming\The Creative Assembly\Shogun2\save_games

share with me your strategies too~!

Tuesday, November 1, 2011

[Arduino] water sensor


I was tinkering with the idea of water sensing with arduino. The rain sensor / water sensing kit/ water detector/ is kind of hard to come by from the Internet stores. Courtesy of Mr.ChongSP, I get to sample his water detector PCB.
Thanks!
The concept of working is the gap between the PCB routes will close when there is a water droplet run across it. Water conducts electricity.  With the appropriate pull up resistor connected with the PCB kit as per the diagram below, we could get the components up within minutes.
Quickly I hook it up with my arduino and used the "button" sample code. i.e the switch button is now my water detector. If there is water, light up the LED, and if there is none off the led......


Now, here comes the interesting part.
1. instead of the usual project of "detect rain-retrieve-laundry" type of application, can we have something more interesting????? I have at least one in mind... hehe
2. is there a way i could do away with the PCB water detector, it looks kinda out of reach to me. Sure! how about using double row male PCB header?? hehe