Created
December 11, 2014 07:48
-
-
Save Jennaltj/e585414ff609c1afa70f to your computer and use it in GitHub Desktop.
Floating City
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int readValue; | |
const int buttonPin = 4; | |
const int buttonPin2 = 5; | |
void setup() | |
{ | |
pinMode(12, OUTPUT); | |
pinMode(9, OUTPUT); | |
digitalWrite(9,HIGH); | |
pinMode(10, OUTPUT); | |
pinMode(4,INPUT); | |
pinMode(5,INPUT); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
readValue = Serial.read(); | |
if (Serial.available()>0) | |
{ | |
Serial.println(readValue); | |
// =================== | |
digitalWrite(12, LOW); | |
digitalWrite(9, LOW); | |
digitalWrite(13,LOW); | |
digitalWrite(9, LOW); | |
if(readValue == 'L') | |
{ | |
analogWrite(11,255); | |
analogWrite(3,0); | |
} | |
else if(readValue == 'R') | |
{ | |
analogWrite(11,0); | |
analogWrite(3,255); | |
} | |
else if(readValue == 'G') | |
{ | |
analogWrite(11,255); | |
analogWrite(3,255); | |
} | |
else if(readValue =='S') | |
{ | |
analogWrite(11,0); | |
analogWrite(3,0); | |
} | |
else | |
{ | |
analogWrite(11,0); | |
analogWrite(3,0); | |
} | |
} | |
else | |
{ | |
Serial.println("no signal"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int buttonPin = 4; | |
const int buttonPin2 = 5; | |
int buttonState = 0; | |
int buttonState2 = 0; | |
void setup() { | |
pinMode(buttonPin,INPUT); | |
Serial.begin (9600); | |
} | |
void loop() { | |
buttonState = digitalRead(buttonPin); | |
buttonState2 = digitalRead(buttonPin2); | |
if (buttonState == 1) | |
{ | |
if(buttonState2 == 1) | |
{ | |
Serial.print('G'); | |
} | |
else | |
{ | |
Serial.print('L'); | |
} | |
} | |
else if(buttonState2 == 1) | |
{ | |
if (buttonState == 1) | |
{ | |
Serial.print('G'); | |
} | |
else | |
{ | |
Serial.print('R'); | |
} | |
} | |
else | |
{ | |
Serial.print('S'); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define PIN 6 | |
#include <Adafruit_NeoPixel.h> | |
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800); | |
const int pingPin = 7; | |
int ledPin = 6; | |
//-------denoise---------------- | |
int denoise[10]; | |
int temp = 0; | |
//========================denoise | |
void setup() | |
{ | |
Serial.begin(9600); | |
strip.begin(); | |
strip.show(); | |
} | |
void loop() | |
{ | |
//--------ping-------- | |
pinMode(ledPin, OUTPUT); | |
long duration, distance; | |
pinMode(pingPin, OUTPUT); | |
digitalWrite(pingPin, LOW); | |
delayMicroseconds(2); | |
digitalWrite(pingPin, HIGH); | |
delayMicroseconds(5); | |
digitalWrite(pingPin, LOW); | |
pinMode(pingPin, INPUT); | |
duration = pulseIn(pingPin, HIGH); | |
distance = microsecondsToCentimeters(duration); | |
Serial.print(distance); | |
Serial.print("cm"); | |
colorWipe(strip.Color(0, 0, 255), 10); | |
//-----denoise | |
for(int i = 0; i < 10; i++) | |
{ | |
denoise[i] = distance; | |
} | |
for(int i = 0; i < 10 ; i++) | |
{ | |
for(int j = 0; j< 10 - i; j++) | |
{ | |
if(denoise[i] > denoise[i+1]) | |
{ | |
temp = denoise[i]; | |
denoise[i] = denoise[i+1]; | |
denoise[i+1] = temp; | |
} | |
} | |
} | |
distance = (denoise[4] + denoise[5]) / 2; | |
//============denoise | |
if (distance<= 80) | |
{ | |
rainbow(0); | |
} | |
else | |
{ | |
digitalWrite(6, LOW); | |
} | |
} | |
void colorWipe(uint32_t c, uint8_t wait) { | |
for(uint16_t i=0; i<strip.numPixels(); i++) { | |
strip.setPixelColor(i, c); | |
strip.show(); | |
delay(wait); | |
} | |
} | |
void rainbow(uint8_t wait) { | |
float i, j; | |
for(j=0; j<256; j++) { | |
for(i=0; i<strip.numPixels(); i += 0.5) { | |
strip.setPixelColor(i, Wheel(i+j)); | |
} | |
strip.show(); | |
} | |
} | |
long microsecondsToCentimeters(long microseconds) | |
{ | |
return microseconds / 29 / 2; | |
} | |
uint32_t Wheel(float WheelPos) { | |
WheelPos = 255 - WheelPos; | |
if(WheelPos < 85) { | |
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); | |
} | |
else if(WheelPos < 170) { | |
WheelPos -= 85; | |
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); | |
} | |
else { | |
WheelPos -= 170; | |
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment