Some pretty cool Arduino examples
Arduino EMF Detector
This project, found on YouTube shows how to turn an Arduino micro-controller into sensor of invisible electromagnetic fields using simple wire, a resistor, and an LED.
Aaron ALAI's EMF detector project is awesomely simple to make and fun to use. An upgraded version can be built using an LED bar-graph for more 'meter-like' functionality.
This project is really really cool and would be a great way for someone to find where they are wasting electricity in their house in a fun and easy way. This doesn't really relate to our Stonehouse project but goes to show the possibilities of Arduino are really wide ranging.
I might even give this a go in my own time when the project is completed!
The Code...
As you can see the code is really simple to do as well, showing how accessable arduino is to anyone with a little bit of knowledge... compared to say... JAVA! -.-
EMF Detector Averaging Code
// Aaron ALAI EMF Detector May 28th 2009 VERSION 1.1
// aaronalai1@gmail.com
// contains code for averaging sensor data
#define sample 300 //this is how many samples the device takes per reading
//more information for #define http://arduino.cc/en/Reference/Define
int inPin = 5; //analog 5
float val; //where to store info from analog 5
int pin11 = 11; //output of red led
int array1[sample]; //creates an array with number of elements equal to "sample"
//more information about arrays http://arduino.cc/en/Reference/Array
unsigned long averaging; //the program uses this variable to store the sum of each array it makes
void setup() {
Serial.begin(9600);
}
void loop() {
for(int i = 0; i < averaging =" averaging" val =" averaging" val =" constrain(val," val =" map(val," averaging =" 0;" inpin =" 5;" pin11 =" 11;" i =" 0;" averaging =" averaging" val =" averaging" val =" constrain(val," val =" map(val," averaging =" 0;" inpin =" 5;" pin11 =" 11;" i =" 0;" averaging =" averaging" val =" averaging" val =" constrain(val," val =" map(val," averaging =" 0;"
Instead of chaining multiple guitar effects in search of a new sound, the maker of this video decided to mod just one. Using an Arduino microcontroller board + digi-pot chip, he was able to add a variable gating effect to a fuzz pedal.
The Code...
http://makezine.googlecode.com/files/WavePot-090819a.zip
Helicopter Game
This helicopter game is made using arduino, and is similar to the popular copter game online, the refresh rate is a bit slow but the game is simple and engaging.
The Code
This code is more in-depth but is do-able
#include
#include "Arial14.h"
#include "SystemFont5x7.h"
/**
* Helicopter Game v0.1
* By Dave de Fijter
* Free to use and abuse :)
*
* Uses the ks0108 library from the arduino playground:
* http://www.arduino.cc/playground/Code/GLCDks0108
*/
int position = 5; // Initial y-position of the helicopter
unsigned int screenwidth = 128; // The width of the screen in pixels (duh)
unsigned int screenheight = 64; // The height of the screen in pixels (duh)
unsigned int playerwidth = 10; // The width of the helicopter sprite
unsigned int playerheight = 5; // The height of the helicopter sprite
unsigned int max_position; // The maximum y-position of the helicopter
unsigned int buttonPin = 12; // The arduino pin number of the play-button
unsigned long xpos = 1; // The x-position of the helicopter ;)
unsigned int iters = 0; // Block iterations, also represents your score
boolean running = true; // Flag that marks if the game is running or not
unsigned int ry; // The y location of the current block to avoid
unsigned int minblock = 19; // Minimum size
unsigned int blocksize = 19; // The startsize of the blocks
unsigned int maxblock = 30; // The maximum size of a block; increase for more difficulty
void setup() {
// Reset the defaults because we wan't te reset the game after a game over
running = true;
xpos = 1;
iters = 0;
position = 5;
blocksize = 19;
// If the button is hold invert the screen, otherwise play it like it's normal
pinMode(buttonPin, INPUT);
if(digitalRead(buttonPin) == LOW) {
GLCD.Init(INVERTED);
} else {
GLCD.Init(NON_INVERTED);
}
GLCD.ClearScreen();
// Calculate the maximum y position of the helicopter
max_position = screenheight - playerheight - 2;
// Show the introduction screen
intro();
// Seed the random generator from the unused analog 5 input (noise)
randomSeed(analogRead(5));
}
void intro() {
// Draw the introtext and wait for a second before starting the game
GLCD.ClearScreen();
GLCD.SelectFont(Arial_14);
GLCD.GotoXY(40, 26);
GLCD.Puts("HeliGame");
delay(1000);
GLCD.ClearScreen();
DrawScene();
}
void DrawPlayer(int y) {
// Remove the last helicopter and draw a new one on the given y position :)
GLCD.FillRect(0, position, 10, 5, WHITE); // Clear the last heli
GLCD.DrawLine(1, y, 8, y, BLACK); // X,Y,X,Y, BLACK
if(xpos % 3 == 0) {
GLCD.SetDot(2, y, WHITE);
GLCD.SetDot(4, y, WHITE);
GLCD.SetDot(6, y, WHITE);
}
GLCD.SetDot(5, y + 1, BLACK);
GLCD.SetDot(1, y + 2, BLACK);
GLCD.DrawLine(4, y + 2, 7, y + 2, BLACK);
GLCD.DrawLine(1, y + 3, 4, y + 3, BLACK);
GLCD.SetDot(8, y + 3, BLACK);
GLCD.DrawLine(4, y + 4, 7, y + 4, BLACK);
position = y;
}
void GameOver() {
// Shop this screen when it's a "Game Over"
// Delay for a sec after that so the reset won't get triggered by accident
// After that second the game can be reset
// Hold the button for a while for "night" modus ;)
GLCD.ClearScreen();
delay(10);
GLCD.SelectFont(Arial_14);
GLCD.GotoXY(32, 26);
GLCD.Puts("Game Over");
GLCD.SelectFont(System5x7);
GLCD.GotoXY(58, 40);
GLCD.PrintNumber(iters);
running = false;
delay(1000);
}
void Blocks(int x) {
// Draw the blocks to avoid;
// Sorry, only one at a time ;)
if(x / screenwidth > 0) {
if(x % screenwidth == 0) {
//GLCD.ClearScreen();
GLCD.FillRect(0, 1, screenwidth -1, screenheight - 3, WHITE);
ry = random(1, screenheight - (blocksize + 2));
iters++;
}
int rt = screenwidth - (x % screenwidth) - 10;
int rto = screenwidth - (xpos % screenwidth) - 10;
if(rto >= 0) {
GLCD.FillRect(rto, ry, 9, blocksize, WHITE);
}
if(rt >= 0) {
GLCD.FillRect(rt, ry, 9, blocksize, BLACK);
}
if(rt <>= ry && position <= (ry + blocksize)) { // collide GameOver(); } } } xpos = x; } void DrawScene() { // Draw the initial scenery GLCD.DrawLine(0, 0, screenwidth - 1, 0, BLACK); GLCD.DrawLine(0, screenheight - 1, screenwidth - 1, screenheight - 1, BLACK); GLCD.SelectFont(System5x7); } void loop() { // Game code; run the main loop if the game is running; // Otherwise check the button state for a game reset if(running) { if(digitalRead(buttonPin) == LOW) { // Go Up DrawPlayer(position - 1); } else { // Go Down DrawPlayer(position + 1); } GLCD.FillRect(100, 4, 26, 7, WHITE); GLCD.GotoXY(100, 4); GLCD.PrintNumber(iters); Blocks(xpos + 1); // Check for status if(position <> max_position) {
GameOver();
}
int del = 10;
if(iters >= 6 ) {
del = 10;
if(blocksize <= maxblock) {
blocksize = minblock + (iters - 5);
}
} else {
del = 40 - (iters * 5);
}
delay(del);
} else {
if(digitalRead(buttonPin) == LOW) {
delay(200);
setup();
}
}
}
No comments:
Post a Comment