//defines ACT_LED as pin 13
#define ACT_LED 13
//function ran once on startup
void setup()
{
//sets up ACT_LED (Pin D13) as an output
pinMode(ACT_LED, OUTPUT);
}
//forever loop
void loop()
{
//turns the led OFF
digitalWrite(ACT_LED, HIGH);
// waits 1 second
delay(1000);
//turns the led ON
digitalWrite(ACT_LED, LOW);
delay(1000);
// wait one second
}
//defines BUTTON_PIN as pin 2
#define BUTTON_PIN 2
//function ran once on startup
void setup()
{
//initializes serial connection at baud rate 9600
Serial.begin(9600);
//initalizes pin D2 (button), to trigger interuptHanlder function when D2 goes form high to low.
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), interuptHandler, FALLING);
}
//forever loop
void loop()
{
//do nothing or something
}
//when the button is pressed anything happening
//in void loop is halted and interuptHandler()
//is executed, in this case a message is printed
void interuptHandler()
{
Serial.println("Hello from Axiometa Spark - you pressed a button");
}
//defines ACT_LED as pin 13
#define ACT_LED 13
//defines LDR_PIN as pin A3
#define LDR_PIN A3
//function ran once on startup
void setup()
{
//sets up LDR_PIN (Pin A3) as an input
pinMode(LDR_PIN, INPUT);
//sets up ACT_LED (Pin D13) as an output
pinMode(ACT_LED, OUTPUT);
}
//forever loop
void loop()
{
//dataLDR stores integer data sampled from analog pin 3 (0-1023)
int dataLDR = analogRead(LDR_PIN);
// if sampled data is greater than 400, the led will turn off
if (dataLDR > 400)
{
digitalWrite(ACT_LED, HIGH);
}
// if sampled data is lower than 400, the led will turn on
else
{
digitalWrite(ACT_LED, LOW);
}
}
//defines PWM_LED as pin 10
#define PWM_LED 10
//function ran once on startup
void setup()
{
//sets up PWM_LED (Pin D10) as an output
pinMode(PWM_LED, OUTPUT);
}
//forever loop
void loop()
{
//Changes voltage on the D10 from 0-255 where o is 0V and 255 is 5V. With a step of +10every 30ms
for (int pwmValue = 0 ; pwmValue <= 255; pwmValue += 10)
{
analogWrite(PWM_LED, pwmValue);
delay(30);
}
//Changes voltage on the D10 from 255-0 where o is 0V and 255 is 5V. With a step of -10 every 30ms
for (int pwmValue = 255 ; pwmValue >= 0; pwmValue -= 10)
{
analogWrite(PWM_LED, pwmValue);
delay(30);
}
}
#define ACT_LED 13
#define PWM_LED 10
#define BUTTON_PIN 2
#define LDR_PIN A3
void setup()
{
Serial.begin(9600);
pinMode(ACT_LED, OUTPUT);
pinMode(PWM_LED, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(BUTTON_PIN), interuptHandler, FALLING);
startupLED();
}
void loop()
{
lightDetection(); //if the surrounding light is too low, the led turns on
PWM(); //fades a PWM LED
}
void startupLED()
{
for (unsigned int i = 0; i < 5; i++)
{
digitalWrite(13, HIGH); delay(100);
digitalWrite(13, LOW); delay(100);
}
}
void lightDetection()
{
int dataLDR = analogRead(LDR_PIN);
if (dataLDR > 400)
{
digitalWrite(ACT_LED, HIGH);
}
else
{
digitalWrite(ACT_LED, LOW);
}
}
void PWM()
{
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 15)
{
analogWrite(PWM_LED, fadeValue);
delay(30);
}
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 15)
{
analogWrite(PWM_LED, fadeValue);
delay(30);
}
}
void interuptHandler()
{
Serial.println("Hello from Axiometa Spark - you pressed a button");
}