Fab Academy 2020 - "How to make almost anything"
Project Development
int motor =6; int sensor_pin =13; void setup() { pinMode(motor, OUTPUT); pinMode(sensor_pin, INPUT); } void loop() { if(digitalRead(13) == HIGH) { digitalWrite(6, HIGH); } else { digitalWrite(motor, LOW); } }
int nn =10;
int r,g,b;
int motor =6;
int sensor_pin =13;
#include
#ifdef __AVR__
#include
#endif #define PIN 11
#define NUMPIXELS 45
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 50
void setup() {
pinMode(motor, OUTPUT);
pinMode(sensor_pin, INPUT);
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
clock_prescale_set(clock_div_1);
#endif
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop() {
pixels.clear();
if(digitalRead(sensor_pin) == HIGH)
{
digitalWrite(motor, HIGH); //to let motor go on
for(int i=0; i{
pixels.setPixelColor(i, pixels.Color(0, 150, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
if(digitalRead(sensor_pin) == LOW) // this part to interrupt the current for loop
return 0;
}
}
else
{
pixels.clear(); // Set all pixel colors to 'off'
digitalWrite(motor, LOW);
}
if(digitalRead(sensor_pin) == HIGH)
return 0;
pixels.clear();
// Coloring Part
for(int i=0; ipixels.setPixelColor(i, pixels.Color(255,0,0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}
if(digitalRead(sensor_pin) == HIGH)
return 0;
for(int i=0; ipixels.setPixelColor(i, pixels.Color(255,255,0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}
if(digitalRead(sensor_pin) == HIGH)
return 0;
for(int i=0; ipixels.setPixelColor(i, pixels.Color(0,255, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}
if(digitalRead(sensor_pin) == HIGH)
return 0;
for(int i=0; ipixels.setPixelColor(i, pixels.Color(0,255,255));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}
if(digitalRead(sensor_pin) == HIGH)
return 0;
for(int i=0; ipixels.setPixelColor(i, pixels.Color(0,0, 255));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}
if(digitalRead(sensor_pin) == HIGH)
return 0;
for(int i=0; ipixels.setPixelColor(i, pixels.Color(255,0, 255));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}
if(digitalRead(sensor_pin) == HIGH)
return 0;
for(int i=0; ipixels.setPixelColor(i, pixels.Color(255,255, 255));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(nn);
}
}