All posts by qingyuli

lol shield flying plane

I try to make a plane is moving  through the moving of cloud . Fortunately , everything works well .

 

 

 

PROGMEM const uint16_t BitMap[][9] = {
//Diaganal swipe across the screen
{ 6 ,
6159 ,
15424 ,
320 ,
496 ,
320 ,
70 ,
6159 ,
15360 },

{ 6 ,
6159 ,
15424 ,
320 ,
496 ,
320 ,
70 ,
6159 ,
15360 },

{ 6 ,
6159 ,
15424 ,
320 ,
496 ,
320 ,
70 ,
6159 ,
15360 },

{ 24 ,
8252 ,
12352 ,
320 ,
496 ,
320 ,
65 ,
1539 ,
3840 },

{ 24 ,
8252 ,
12352 ,
320 ,
496 ,
320 ,
65 ,
1539 ,
3840 },

{ 24 ,
8252 ,
12352 ,
320 ,
496 ,
320 ,
65 ,
1539 ,
3840 },

{ 96 ,
240 ,
64 ,
320 ,
496 ,
320 ,
64 ,
384 ,
960 },

{ 96 ,
240 ,
64 ,
320 ,
496 ,
320 ,
64 ,
384 ,
960 },

{ 96 ,
240 ,
64 ,
320 ,
496 ,
320 ,
64 ,
384 ,
960 },

{ 768 ,
1921 ,
67 ,
320 ,
496 ,
320 ,
8256 ,
12384 ,
240 },

{ 768 ,
1921 ,
67 ,
320 ,
496 ,
320 ,
8256 ,
12384 ,
240 },

{ 768 ,
1921 ,
67 ,
320 ,
496 ,
320 ,
8256 ,
12384 ,
240 },

{ 3072 ,
7686 ,
79 ,
320 ,
496 ,
320 ,
6208 ,
15384 ,
60 },

{ 3072 ,
7686 ,
79 ,
320 ,
496 ,
320 ,
6208 ,
15384 ,
60 },

{ 3072 ,
7686 ,
79 ,
320 ,
496 ,
320 ,
6208 ,
15384 ,
60 },

{ 12288 ,
14360 ,
60 ,
320 ,
496 ,
320 ,
1600 ,
3846 ,
15 },

{ 0 ,
97 ,
240 ,
320 ,
496 ,
320 ,
448 ,
961 ,
3 },

{ 0 ,
97 ,
240 ,
320 ,
496 ,
320 ,
448 ,
961 ,
3 },

{ 0 ,
97 ,
240 ,
320 ,
496 ,
320 ,
448 ,
961 ,
3 },

{ 3 ,
391 ,
960 ,
320 ,
496 ,
320 ,
96 ,
8432 ,
12288 },

{ 3 ,
391 ,
960 ,
320 ,
496 ,
320 ,
96 ,
8432 ,
12288 },

{ 3 ,
391 ,
960 ,
320 ,
496 ,
320 ,
96 ,
8432 ,
12288 },

{ 12 ,
1566 ,
3840 ,
320 ,
496 ,
320 ,
24 ,
6204 ,
15360 },

{ 12 ,
1566 ,
3840 ,
320 ,
496 ,
320 ,
24 ,
6204 ,
15360 },

{0, 0, 0, 0, 0, 0, 0, 0, 0},
{18000}
};

void setup() {
LedSign::Init(DOUBLE_BUFFER | GRAYSCALE); //Initializes the screen
}
void loop() {
for (uint8_t gray = 1; gray < SHADES; gray++)
DisplayBitMap(gray); //Displays the bitmap
}

void DisplayBitMap(uint8_t grayscale)
{
boolean run=true; //While this is true, the screen updates
byte frame = 0; //Frame counter
byte line = 0; //Row counter
unsigned long data; //Temporary storage of the row data
unsigned long start = 0;

while(run == true) {

for(line = 0; line < 9; line++) {

//Here we fetch data from program memory with a pointer.
data = pgm_read_word_near (&BitMap[frame][line]);

//Kills the loop if the kill number is found
if (data==18000){
run=false;
}

//This is where the bit-shifting happens to pull out
//each LED from a row. If the bit is 1, then the LED
//is turned on, otherwise it is turned off.
else for (byte led=0; led<14; ++led) {
if (data & (1<<led)) {
LedSign::Set(led, line, grayscale);
}
else {
LedSign::Set(led, line, 0);
}
}
}

LedSign::Flip(true);

unsigned long end = millis();
unsigned long diff = end – start;
if ( start && (diff < blinkdelay) )
delay( blinkdelay – diff );
start = end;

frame++;
}
}

mid term zen circle drawing

QQ图片20141108043505 QQ图片20141108043519 QQ图片20141108043741

People like  zazen to improve their self control .  It’s through the control of breathing and heartbeat . So i want to try to use a pulse sensor to  make some interaction with zen arts , a  brush pen draw a circle according to the BPM.

#include <Stepper.h>

const int stepsPerRevolution = 512; // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);

// VARIABLES
int pulsePin = 0; // Pulse Sensor purple wire connected to analog pin 0
int blinkPin = 13; // pin to blink led at each beat
int fadePin = 5; // pin to do fancy classy fading blink at each beat
int fadeRate = 0;

int steps=0;// used to fade LED on with PWM on fadePin

boolean fadeIn = false;
// these variables are volatile because they are used during the interrupt service routine!
volatile int BPM; // used to hold the pulse rate
volatile int Signal; // holds the incoming raw data
volatile int IBI = 600; // holds the time between beats, the Inter-Beat Interval
volatile boolean Pulse = false; // true when pulse wave is high, false when it’s low
volatile boolean QS = false;
int times=0;// becomes true when Arduoino finds a beat.
void setup(){
pinMode(blinkPin,OUTPUT); // pin that will blink to your heartbeat!
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
pinMode(6,OUTPUT);
pinMode(2,OUTPUT); // pin that will fade to your heartbeat!
Serial.begin(115200);
myStepper.setSpeed(30); // we agree to talk fast!
interruptSetup();
// sets up to read Pulse Sensor signal every 2mS
// UN-COMMENT THE NEXT LINE IF YOU ARE POWERING The Pulse Sensor AT LOW VOLTAGE,
// AND APPLY THAT VOLTAGE TO THE A-REF PIN
//analogReference(EXTERNAL);
}

void loop(){
sendDataToProcessing(‘S’, Signal);
steps=map(BPM,50,150,140,20); // send Processing the raw Pulse Sensor data
if (QS == true){ // Quantified Self flag is true when arduino finds a heartbeat
fadeRate = 255; // Set ‘fadeRate’ Variable to 255 to fade LED with pulse

fadeIn = true;

sendDataToProcessing(‘B’,BPM); // send heart rate with a ‘B’ prefix
sendDataToProcessing(‘Q’,IBI); // send time between beats with a ‘Q’ prefix
QS = false;
times=times+1; // reset the Quantified Self flag for next time
}
if (times ==5){

myStepper.step(steps);
times=0;
ledFadeToBeat();
}
if (times ==1){
fadeRate -= 30; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(6,fadeRate);

}
if (times ==2){
fadeRate -= 30; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(5,fadeRate);

}
if (times ==3){
fadeRate -= 30; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(4,fadeRate);

}
if (times ==4){
fadeRate -= 30; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(2,fadeRate);

}

delay(20); // take a break
}
void ledFadeToBeat(){
fadeRate -= 15; // set LED fade value
fadeRate = constrain(fadeRate,0,255); // keep LED fade value from going into negative numbers!
analogWrite(5,fadeRate);
analogWrite(4,fadeRate);
analogWrite(6,fadeRate);
analogWrite(2,fadeRate);

// fade LED
}
void sendDataToProcessing(char symbol, int data ){
Serial.print(symbol); // symbol prefix tells Processing what type of data is coming
Serial.println(data); // the data to send culminating in a carriage return
}

homework5: musical note

i find that the shape of the rotate device is like the music note , so i have this idea .

#include <Servo.h>
Servo myservo;
int potpin = 0;
int val;
int voice;
int speaker = 10;

void setup()
{
Serial.begin(9600);
myservo.attach(9);
pinMode(speaker,OUTPUT);
}
void loop()
{

val = analogRead(potpin);

voice = map(val,0,1023,0,4000);
val = map(val, 0, 1023, 0, 180);

tone(speaker,voice);

myservo.write(val);

delay(15);
}

homework3 : distance

I use a range sensor to calculate the distance like a bat through the theory of per centimeter need 29 milliseconds for sound .

 

 

 

 

 

 

const int pingPin = 7;
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {

Serial.begin(9600);

lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);

}

void loop()
{

pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
int distance = pulseIn(pingPin, HIGH);
distance= distance/58;
delay(200);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Distance is”);
lcd.setCursor(0,1);
lcd.print(distance);
lcd.print(“cm”);
}

PCOM assignment 1 : a button

here is the code :

int led = 13;
int controller = 2;
int n =0;

void setup()
{
pinMode(2,INPUT);
pinMode(13, OUTPUT);
pinMode(4,OUTPUT);
}

void loop()
{
n = digitalRead(2);
Serial.println(n);
if (n == HIGH)
{

digitalWrite(13,HIGH);
digitalWrite(4, LOW);

}
else {

digitalWrite(13, LOW);
digitalWrite(4, HIGH);
}
}

 

 

i  make a button to control one RGB led’s light color which is also a  switch for the  other 2 led .

here is the video