lucy, the magic-6-cube.
Lucifer was intended to be a Magic-8-Ball, but she was born different. She was born a Magic-6-Cube. On top of that, she has struggled with her name all her life, so to fight it off, she decided she would make people love her by always answering positively. This means, of course, that sometimes people might ask the wrong question, and a positive answer might not be that good for them. But Lucy (as she prefers to be called) is happy whenever she can make one person’s day brighter!
/* Requires LoL Shield library, at least V0.2Beta http://code.google.com/p/lolshield/downloads/list And the Font.cpp from LoL_Shield-100915.zip on ikkei's page: http://web.mac.com/kxm_ikkei/Site/LoL.html Based on original TEXT SAMPLE CODE for LOL Shield for Arduino Copyright 2009/2010 Benjamin Sonntag <benjamin@sonntag.fr> http://benjamin.sonntag.fr/ (This version edited by Walfas) */ #include "Charliplexing.h" #include "Font.h" #include "WProgram.h" // Technically the number of columns of LEDs minus one #define SCREEN_WIDTH 13 // Scroll delay: lower values result in faster scrolling #define SCROLL_DELAY 80 /* How long to wait after the last letter before going back to the beginning and repeating */ #define REPEAT_DELAY 500 // SMILEY FACE byte line = 0; //Row counter char buffer[10]; int value; // BUTTON int buttonPin = A5; // the number of the pushbutton pin int lightPin = A0; int ledPin = A2; int val = 0; int buttonState = 0; // variable for reading the pushbutton status int textLength, totalPixels; char text[9]; int r=0; void setup() { Serial.begin(9600); LedSign::Init(); pinMode(ledPin, OUTPUT); pinMode(buttonPin, INPUT); pinMode(lightPin, INPUT); } void loop() { buttonState = digitalRead(buttonPin); val = analogRead(lightPin); // Read the value (amount of light) from photocell Serial.println(val); // Print out the value to the serial port // smiley(); if(val <= 330){ digitalWrite(ledPin, HIGH); } else{ digitalWrite(ledPin, LOW); } // BUTTON if (buttonState == HIGH) { r = int(random(4)); if(r==0){ text[0] = 'H'; text[1] = 'E'; text[2] = 'L'; text[3] = 'L'; text[4] = ' '; text[5] = 'Y'; text[6] = 'E'; text[7] = 'A'; text[8] = 'H'; } else if(r==1) { text[0] = 'B'; text[1] = 'E'; text[2] = 'T'; text[3] = ' '; text[4] = 'O'; text[5] = 'N'; text[6] = ' '; text[7] = 'I'; text[8] = 'T'; } else if(r==2) { text[0] = 'A'; text[1] = 'S'; text[2] = 'K'; text[3] = ' '; text[4] = 'A'; text[5] = 'G'; text[6] = 'A'; text[7] = 'I'; text[8] = 'N'; } else if(r==3) { text[0] = 'W'; text[1] = 'O'; text[2] = 'R'; text[3] = 'D'; text[4] = ' '; text[5] = ' '; text[6] = ' '; text[7] = ' '; text[8] = ' '; } getLength(text, &textLength, &totalPixels); int x=0; for(int j=SCREEN_WIDTH; j>-totalPixels-SCREEN_WIDTH; j--) { x=j; LedSign::Clear(); for(int i=0; i<textLength; i++) { x += Font::Draw(text[i],x,0); if (x>=SCREEN_WIDTH) break; } delay(SCROLL_DELAY); } delay(REPEAT_DELAY); } } // FUNCTION void smiley(){ delay(400); DisplayBitMap(0); DisplayBitMap(1560); DisplayBitMap(3900); DisplayBitMap(1560); DisplayBitMap(0); DisplayBitMap(1008); DisplayBitMap(480); DisplayBitMap(192); DisplayBitMap(0); delay(400); DisplayBitMap(1560); DisplayBitMap(3900); DisplayBitMap(1560); DisplayBitMap(0); DisplayBitMap(4092); DisplayBitMap(2040); DisplayBitMap(1008); DisplayBitMap(480); DisplayBitMap(0); delay(400); DisplayBitMap(0); DisplayBitMap(1560); DisplayBitMap(3900); DisplayBitMap(1560); DisplayBitMap(0); DisplayBitMap(2040); DisplayBitMap(1008); DisplayBitMap(480); DisplayBitMap(0); delay(400); DisplayBitMap(0); DisplayBitMap(0); DisplayBitMap(1560); DisplayBitMap(3900); DisplayBitMap(1560); DisplayBitMap(0); DisplayBitMap(1008); DisplayBitMap(480); DisplayBitMap(192); } // FUNCTION void DisplayBitMap(int lineint) { //int data[9] = {95, 247, 123, 511, 255, 1, 5, 31, 15}; //for(line = 0; line < 9; line++) { for (byte led=0; led<14; ++led) { if (lineint & (1<<led)) { LedSign::Set(led, line, 1); } else { LedSign::Set(led, line, 0); } } line++; if(line >= 9) line = 0; } // FUNCTION void getLength(char* charArray, int* lengthPtr, int* pixelPtr) { /* Finds the length of a string in terms of characters and pixels and assigns them to the variable at addresses lengthPtr and pixelPtr, respectively. */ int charCount = 0, pixelCount = 0; char * charPtr = charArray; // Count chars until newline or null character reached while (*charPtr != '\0' && *charPtr != '\n') { charPtr++; charCount++; /* Increment pixelCount by the number of pixels the current character takes up horizontally. */ pixelCount += Font::Draw(*charPtr,-SCREEN_WIDTH,0); } *pixelPtr = pixelCount; *lengthPtr = charCount; }
Reply