arduino-mk 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +60 -0
- data/lib/arduino-mk.rb +10 -0
- data/lib/arduino-mk/base.rb +61 -0
- data/lib/arduino-mk/error_improver.rb +42 -0
- data/lib/arduino-mk/makefile/runner.rb +23 -0
- data/lib/arduino-mk/makefile/template.rb +27 -0
- data/lib/arduino-mk/null_project.rb +5 -0
- data/lib/arduino-mk/null_project/null.c +1 -0
- data/lib/arduino-mk/option_parser.rb +35 -0
- data/lib/arduino-mk/project_copier.rb +9 -0
- data/vendor/Arduino-Makefile/Arduino.mk +1306 -0
- data/vendor/Arduino-Makefile/CONTRIBUTING.md +35 -0
- data/vendor/Arduino-Makefile/Common.mk +46 -0
- data/vendor/Arduino-Makefile/HISTORY.md +225 -0
- data/vendor/Arduino-Makefile/README.md +189 -0
- data/vendor/Arduino-Makefile/ard-reset-arduino.1 +48 -0
- data/vendor/Arduino-Makefile/arduino-mk-vars.md +1101 -0
- data/vendor/Arduino-Makefile/bin/ard-reset-arduino +38 -0
- data/vendor/Arduino-Makefile/chipKIT.mk +109 -0
- data/vendor/Arduino-Makefile/examples/ATtinyBlink/ATtinyBlink.ino +23 -0
- data/vendor/Arduino-Makefile/examples/ATtinyBlink/Makefile +13 -0
- data/vendor/Arduino-Makefile/examples/AnalogInOutSerial/AnalogInOutSerial.ino +53 -0
- data/vendor/Arduino-Makefile/examples/AnalogInOutSerial/Makefile +4 -0
- data/vendor/Arduino-Makefile/examples/Blink/Blink.ino +19 -0
- data/vendor/Arduino-Makefile/examples/Blink/Makefile +5 -0
- data/vendor/Arduino-Makefile/examples/BlinkChipKIT/BlinkChipKIT.pde +19 -0
- data/vendor/Arduino-Makefile/examples/BlinkChipKIT/Makefile +5 -0
- data/vendor/Arduino-Makefile/examples/BlinkInAVRC/Makefile +16 -0
- data/vendor/Arduino-Makefile/examples/BlinkInAVRC/blink.c +38 -0
- data/vendor/Arduino-Makefile/examples/BlinkWithoutDelay/BlinkWithoutDelay.ino +65 -0
- data/vendor/Arduino-Makefile/examples/BlinkWithoutDelay/Makefile +4 -0
- data/vendor/Arduino-Makefile/examples/Fade/Fade.ino +31 -0
- data/vendor/Arduino-Makefile/examples/Fade/Makefile +4 -0
- data/vendor/Arduino-Makefile/examples/HelloWorld/HelloWorld.ino +58 -0
- data/vendor/Arduino-Makefile/examples/HelloWorld/Makefile +4 -0
- data/vendor/Arduino-Makefile/examples/MakefileExample/Makefile-example.mk +55 -0
- data/vendor/Arduino-Makefile/examples/README.md +7 -0
- data/vendor/Arduino-Makefile/examples/TinySoftWareSerial/Makefile +14 -0
- data/vendor/Arduino-Makefile/examples/TinySoftWareSerial/TinySoftwareSerial.ino +12 -0
- data/vendor/Arduino-Makefile/examples/WebServer/Makefile +6 -0
- data/vendor/Arduino-Makefile/examples/WebServer/WebServer.ino +82 -0
- data/vendor/Arduino-Makefile/examples/master_reader/Makefile +6 -0
- data/vendor/Arduino-Makefile/examples/master_reader/master_reader.ino +32 -0
- data/vendor/Arduino-Makefile/examples/toneMelody/Makefile +4 -0
- data/vendor/Arduino-Makefile/examples/toneMelody/pitches.h +95 -0
- data/vendor/Arduino-Makefile/examples/toneMelody/toneMelody.ino +49 -0
- data/vendor/Arduino-Makefile/licence.txt +502 -0
- data/vendor/Arduino-Makefile/packaging/debian/README.md +23 -0
- data/vendor/Arduino-Makefile/packaging/fedora/README.md +39 -0
- data/vendor/Arduino-Makefile/packaging/fedora/arduino-mk.spec +70 -0
- metadata +110 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
|
3
|
+
from __future__ import print_function
|
4
|
+
import serial
|
5
|
+
import os.path
|
6
|
+
import argparse
|
7
|
+
from time import sleep
|
8
|
+
|
9
|
+
parser = argparse.ArgumentParser(description='Reset an Arduino')
|
10
|
+
parser.add_argument('--caterina', action='store_true', help='Reset a Leonardo, Micro, Robot or LilyPadUSB.')
|
11
|
+
parser.add_argument('--verbose', action='store_true', help="Watch what's going on on STDERR.")
|
12
|
+
parser.add_argument('--period', default=0.1, help='Specify the DTR pulse width in seconds.')
|
13
|
+
parser.add_argument('port', nargs=1, help='Serial device e.g. /dev/ttyACM0')
|
14
|
+
args = parser.parse_args()
|
15
|
+
|
16
|
+
if args.caterina:
|
17
|
+
if args.verbose: print('Forcing reset using 1200bps open/close on port %s' % args.port[0])
|
18
|
+
ser = serial.Serial(args.port[0], 57600)
|
19
|
+
ser.close()
|
20
|
+
ser.open()
|
21
|
+
ser.close()
|
22
|
+
ser.setBaudrate(1200)
|
23
|
+
ser.open()
|
24
|
+
ser.close()
|
25
|
+
sleep(1)
|
26
|
+
|
27
|
+
while not os.path.exists(args.port[0]):
|
28
|
+
if args.verbose: print('Waiting for %s to come back' % args.port[0])
|
29
|
+
sleep(1)
|
30
|
+
|
31
|
+
if args.verbose: print('%s has come back after reset' % args.port[0])
|
32
|
+
else:
|
33
|
+
if args.verbose: print('Setting DTR high on %s for %ss' % (args.port[0],args.period))
|
34
|
+
ser = serial.Serial(args.port[0], 115200)
|
35
|
+
ser.setDTR(False)
|
36
|
+
sleep(args.period)
|
37
|
+
ser.setDTR(True)
|
38
|
+
ser.close()
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#
|
2
|
+
# chipKIT extensions for Arduino Makefile
|
3
|
+
# System part (i.e. project independent)
|
4
|
+
#
|
5
|
+
# Copyright (C) 2011, 2012, 2013 Christopher Peplin
|
6
|
+
# <chris.peplin@rhubarbtech.com>, based on work that is Copyright Martin
|
7
|
+
# Oldfield
|
8
|
+
#
|
9
|
+
# This file is free software; you can redistribute it and/or modify it
|
10
|
+
# under the terms of the GNU Lesser General Public License as
|
11
|
+
# published by the Free Software Foundation; either version 2.1 of the
|
12
|
+
# License, or (at your option) any later version.
|
13
|
+
#
|
14
|
+
# Modified by John Wallbank for Visual Studio
|
15
|
+
#
|
16
|
+
# Development changes, John Wallbank,
|
17
|
+
#
|
18
|
+
# - made inclusion of WProgram.h optional so that
|
19
|
+
# including it in the source doesn't mess up compile error line numbers
|
20
|
+
# - parameterised the routine used to reset the serial port
|
21
|
+
#
|
22
|
+
|
23
|
+
########################################################################
|
24
|
+
# Makefile distribution path
|
25
|
+
#
|
26
|
+
|
27
|
+
# The show_config_variable is unavailable before we include the common makefile,
|
28
|
+
# so we defer logging the ARDMK_DIR info until it happens in Arduino.mk
|
29
|
+
ifndef ARDMK_DIR
|
30
|
+
# presume it's the same path to our own file
|
31
|
+
ARDMK_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
|
32
|
+
endif
|
33
|
+
|
34
|
+
include $(ARDMK_DIR)/Common.mk
|
35
|
+
|
36
|
+
ifndef MPIDE_DIR
|
37
|
+
AUTO_MPIDE_DIR := $(firstword \
|
38
|
+
$(call dir_if_exists,/usr/share/mpide) \
|
39
|
+
$(call dir_if_exists,/Applications/Mpide.app/Contents/Resources/Java) )
|
40
|
+
ifdef AUTO_MPIDE_DIR
|
41
|
+
MPIDE_DIR = $(AUTO_MPIDE_DIR)
|
42
|
+
$(call show_config_variable,MPIDE_DIR,[autodetected])
|
43
|
+
else
|
44
|
+
echo $(error "mpide_dir is not defined")
|
45
|
+
endif
|
46
|
+
else
|
47
|
+
$(call show_config_variable,MPIDE_DIR,[USER])
|
48
|
+
endif
|
49
|
+
|
50
|
+
ifndef MPIDE_PREFERENCES_PATH
|
51
|
+
AUTO_MPIDE_PREFERENCES_PATH := $(firstword \
|
52
|
+
$(call dir_if_exists,$(HOME)/.mpide/preferences.txt) \
|
53
|
+
$(call dir_if_exists,$(HOME)/Library/Mpide/preferences.txt) )
|
54
|
+
ifdef AUTO_MPIDE_PREFERENCES_PATH
|
55
|
+
MPIDE_PREFERENCES_PATH = $(AUTO_MPIDE_PREFERENCES_PATH)
|
56
|
+
$(call show_config_variable,MPIDE_PREFERENCES_PATH,[autodetected])
|
57
|
+
endif
|
58
|
+
endif
|
59
|
+
|
60
|
+
# The same as in Arduino, the Linux distribution contains avrdude and #
|
61
|
+
# avrdude.conf in a different location, but for chipKIT it's even slightly
|
62
|
+
# different than the Linux paths for Arduino, so we have to "double override".
|
63
|
+
ifeq ($(CURRENT_OS),LINUX)
|
64
|
+
AVRDUDE_DIR = $(ARDUINO_DIR)/hardware/tools
|
65
|
+
AVRDUDE = $(AVRDUDE_DIR)/avrdude
|
66
|
+
AVRDUDE_CONF = $(AVRDUDE_DIR)/avrdude.conf
|
67
|
+
endif
|
68
|
+
|
69
|
+
PIC32_TOOLS_DIR = $(ARDUINO_DIR)/hardware/pic32/compiler/pic32-tools
|
70
|
+
PIC32_TOOLS_PATH = $(PIC32_TOOLS_DIR)/bin
|
71
|
+
|
72
|
+
ALTERNATE_CORE = pic32
|
73
|
+
ALTERNATE_CORE_PATH = $(MPIDE_DIR)/hardware/pic32
|
74
|
+
ARDUINO_CORE_PATH = $(ALTERNATE_CORE_PATH)/cores/$(ALTERNATE_CORE)
|
75
|
+
ARDUINO_PREFERENCES_PATH = $(MPIDE_PREFERENCES_PATH)
|
76
|
+
ARDUINO_DIR = $(MPIDE_DIR)
|
77
|
+
|
78
|
+
CORE_AS_SRCS = $(ARDUINO_CORE_PATH)/vector_table.S
|
79
|
+
|
80
|
+
ARDUINO_VERSION = 23
|
81
|
+
|
82
|
+
CC_NAME = pic32-gcc
|
83
|
+
CXX_NAME = pic32-g++
|
84
|
+
AR_NAME = pic32-ar
|
85
|
+
OBJDUMP_NAME = pic32-objdump
|
86
|
+
OBJCOPY_NAME = pic32-objcopy
|
87
|
+
SIZE_NAME = pic32-size
|
88
|
+
NM_NAME = pic32-nm
|
89
|
+
|
90
|
+
OVERRIDE_EXECUTABLES = 1
|
91
|
+
CC = $(PIC32_TOOLS_PATH)/$(CC_NAME)
|
92
|
+
CXX = $(PIC32_TOOLS_PATH)/$(CXX_NAME)
|
93
|
+
AS = $(PIC32_TOOLS_PATH)/$(AS_NAME)
|
94
|
+
OBJCOPY = $(PIC32_TOOLS_PATH)/$(OBJCOPY_NAME)
|
95
|
+
OBJDUMP = $(PIC32_TOOLS_PATH)/$(OBJDUMP_NAME)
|
96
|
+
AR = $(PIC32_TOOLS_PATH)/$(AR_NAME)
|
97
|
+
SIZE = $(PIC32_TOOLS_PATH)/$(SIZE_NAME)
|
98
|
+
NM = $(PIC32_TOOLS_PATH)/$(NM_NAME)
|
99
|
+
|
100
|
+
LDSCRIPT = $(call PARSE_BOARD,$(BOARD_TAG),ldscript)
|
101
|
+
LDSCRIPT_FILE = $(ARDUINO_CORE_PATH)/$(LDSCRIPT)
|
102
|
+
|
103
|
+
MCU_FLAG_NAME=mprocessor
|
104
|
+
LDFLAGS += -T$(ARDUINO_CORE_PATH)/$(LDSCRIPT)
|
105
|
+
LDFLAGS += -T$(ARDUINO_CORE_PATH)/chipKIT-application-COMMON.ld
|
106
|
+
CPPFLAGS += -mno-smart-io -fno-short-double
|
107
|
+
CFLAGS_STD =
|
108
|
+
|
109
|
+
include $(ARDMK_DIR)/Arduino.mk
|
@@ -0,0 +1,23 @@
|
|
1
|
+
/*
|
2
|
+
Blink
|
3
|
+
Turns on an LED on for one second, then off for one second, repeatedly.
|
4
|
+
|
5
|
+
This example code is in the public domain.
|
6
|
+
*/
|
7
|
+
|
8
|
+
// Connect a LED to Pin 3. It might be different in different ATtiny micro controllers
|
9
|
+
int led = 3;
|
10
|
+
|
11
|
+
// the setup routine runs once when you press reset:
|
12
|
+
void setup() {
|
13
|
+
// initialize the digital pin as an output.
|
14
|
+
pinMode(led, OUTPUT);
|
15
|
+
}
|
16
|
+
|
17
|
+
// the loop routine runs over and over again forever:
|
18
|
+
void loop() {
|
19
|
+
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
|
20
|
+
delay(1000); // wait for a second
|
21
|
+
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
|
22
|
+
delay(1000); // wait for a second
|
23
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
|
2
|
+
|
3
|
+
# if you have placed the alternate core in your sketchbook directory, then you can just mention the core name alone.
|
4
|
+
ALTERNATE_CORE = attiny
|
5
|
+
# If not, you might have to include the full path.
|
6
|
+
#ALTERNATE_CORE_PATH = /home/sudar/Dropbox/code/arduino-sketches/hardware/attiny/
|
7
|
+
|
8
|
+
BOARD_TAG = attiny85-8
|
9
|
+
ISP_PORT = /dev/ttyACM*
|
10
|
+
|
11
|
+
include $(ARDMK_DIR)/Arduino.mk
|
12
|
+
|
13
|
+
# !!! Important. You have to use make ispload to upload when using ISP programmer
|
@@ -0,0 +1,53 @@
|
|
1
|
+
/*
|
2
|
+
Analog input, analog output, serial output
|
3
|
+
|
4
|
+
Reads an analog input pin, maps the result to a range from 0 to 255
|
5
|
+
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
|
6
|
+
Also prints the results to the serial monitor.
|
7
|
+
|
8
|
+
The circuit:
|
9
|
+
* potentiometer connected to analog pin 0.
|
10
|
+
Center pin of the potentiometer goes to the analog pin.
|
11
|
+
side pins of the potentiometer go to +5V and ground
|
12
|
+
* LED connected from digital pin 9 to ground
|
13
|
+
|
14
|
+
created 29 Dec. 2008
|
15
|
+
modified 30 Aug 2011
|
16
|
+
by Tom Igoe
|
17
|
+
|
18
|
+
This example code is in the public domain.
|
19
|
+
|
20
|
+
*/
|
21
|
+
|
22
|
+
// These constants won't change. They're used to give names
|
23
|
+
// to the pins used:
|
24
|
+
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
|
25
|
+
const int analogOutPin = 9; // Analog output pin that the LED is attached to
|
26
|
+
|
27
|
+
int sensorValue = 0; // value read from the pot
|
28
|
+
int outputValue = 0; // value output to the PWM (analog out)
|
29
|
+
|
30
|
+
void setup() {
|
31
|
+
// initialize serial communications at 9600 bps:
|
32
|
+
Serial.begin(9600);
|
33
|
+
}
|
34
|
+
|
35
|
+
void loop() {
|
36
|
+
// read the analog in value:
|
37
|
+
sensorValue = analogRead(analogInPin);
|
38
|
+
// map it to the range of the analog out:
|
39
|
+
outputValue = map(sensorValue, 0, 1023, 0, 255);
|
40
|
+
// change the analog out value:
|
41
|
+
analogWrite(analogOutPin, outputValue);
|
42
|
+
|
43
|
+
// print the results to the serial monitor:
|
44
|
+
Serial.print("sensor = " );
|
45
|
+
Serial.print(sensorValue);
|
46
|
+
Serial.print("\t output = ");
|
47
|
+
Serial.println(outputValue);
|
48
|
+
|
49
|
+
// wait 10 milliseconds before the next loop
|
50
|
+
// for the analog-to-digital converter to settle
|
51
|
+
// after the last reading:
|
52
|
+
delay(10);
|
53
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/*
|
2
|
+
Blink
|
3
|
+
Turns on an LED on for one second, then off for one second, repeatedly.
|
4
|
+
|
5
|
+
This example code is in the public domain.
|
6
|
+
*/
|
7
|
+
|
8
|
+
void setup() {
|
9
|
+
// initialize the digital pin as an output.
|
10
|
+
// Pin 13 has an LED connected on most Arduino boards:
|
11
|
+
pinMode(13, OUTPUT);
|
12
|
+
}
|
13
|
+
|
14
|
+
void loop() {
|
15
|
+
digitalWrite(13, HIGH); // set the LED on
|
16
|
+
delay(1000); // wait for a second
|
17
|
+
digitalWrite(13, LOW); // set the LED off
|
18
|
+
delay(1000); // wait for a second
|
19
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
/*
|
2
|
+
Blink
|
3
|
+
Turns on an LED on for one second, then off for one second, repeatedly.
|
4
|
+
|
5
|
+
This example code is in the public domain.
|
6
|
+
*/
|
7
|
+
|
8
|
+
void setup() {
|
9
|
+
// initialize the digital pin as an output.
|
10
|
+
// Pin 13 has an LED connected on most Arduino boards:
|
11
|
+
pinMode(13, OUTPUT);
|
12
|
+
}
|
13
|
+
|
14
|
+
void loop() {
|
15
|
+
digitalWrite(13, HIGH); // set the LED on
|
16
|
+
delay(1000); // wait for a second
|
17
|
+
digitalWrite(13, LOW); // set the LED off
|
18
|
+
delay(1000); // wait for a second
|
19
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# This sample Makefile, explains how you can compile plain AVR C file.
|
2
|
+
#
|
3
|
+
# Arduino Make file. Refer to https://github.com/sudar/Arduino-Makefile
|
4
|
+
|
5
|
+
NO_CORE = Yes
|
6
|
+
|
7
|
+
BOARD_TAG = atmega16
|
8
|
+
MCU = atmega16
|
9
|
+
F_CPU = 8000000L
|
10
|
+
|
11
|
+
ISP_PROG = stk500v1
|
12
|
+
AVRDUDE_ISP_BAUDRATE = 19200
|
13
|
+
|
14
|
+
include $(ARDMK_DIR)/Arduino.mk
|
15
|
+
|
16
|
+
# !!! Important. You have to use make ispload to upload when using ISP programmer
|
@@ -0,0 +1,38 @@
|
|
1
|
+
/*
|
2
|
+
* � Anil Kumar Pugalia, 2010. Email: email@sarika-pugs.com
|
3
|
+
*
|
4
|
+
* ATmega48/88/168, ATmega16/32
|
5
|
+
*
|
6
|
+
* Example Blink. Toggles all IO pins at 1Hz
|
7
|
+
*/
|
8
|
+
|
9
|
+
#include <avr/io.h>
|
10
|
+
#include <util/delay.h>
|
11
|
+
|
12
|
+
void init_io(void)
|
13
|
+
{
|
14
|
+
// 1 = output, 0 = input
|
15
|
+
DDRB = 0b11111111; // All outputs
|
16
|
+
DDRC = 0b11111111; // All outputs
|
17
|
+
DDRD = 0b11111110; // PORTD (RX on PD0). Just for demo
|
18
|
+
}
|
19
|
+
|
20
|
+
int main(void)
|
21
|
+
{
|
22
|
+
init_io();
|
23
|
+
|
24
|
+
while (1)
|
25
|
+
{
|
26
|
+
PORTC = 0xFF;
|
27
|
+
PORTB = 0xFF;
|
28
|
+
PORTD = 0xFF;
|
29
|
+
_delay_ms(500);
|
30
|
+
|
31
|
+
PORTC = 0x00;
|
32
|
+
PORTB = 0x00;
|
33
|
+
PORTD = 0x00;
|
34
|
+
_delay_ms(500);
|
35
|
+
}
|
36
|
+
|
37
|
+
return 0;
|
38
|
+
}
|
@@ -0,0 +1,65 @@
|
|
1
|
+
/* Blink without Delay
|
2
|
+
|
3
|
+
Turns on and off a light emitting diode(LED) connected to a digital
|
4
|
+
pin, without using the delay() function. This means that other code
|
5
|
+
can run at the same time without being interrupted by the LED code.
|
6
|
+
|
7
|
+
The circuit:
|
8
|
+
* LED attached from pin 13 to ground.
|
9
|
+
* Note: on most Arduinos, there is already an LED on the board
|
10
|
+
that's attached to pin 13, so no hardware is needed for this example.
|
11
|
+
|
12
|
+
|
13
|
+
created 2005
|
14
|
+
by David A. Mellis
|
15
|
+
modified 8 Feb 2010
|
16
|
+
by Paul Stoffregen
|
17
|
+
|
18
|
+
This example code is in the public domain.
|
19
|
+
|
20
|
+
|
21
|
+
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
|
22
|
+
*/
|
23
|
+
|
24
|
+
// constants won't change. Used here to
|
25
|
+
// set pin numbers:
|
26
|
+
const int ledPin = 13; // the number of the LED pin
|
27
|
+
|
28
|
+
// Variables will change:
|
29
|
+
int ledState = LOW; // ledState used to set the LED
|
30
|
+
long previousMillis = 0; // will store last time LED was updated
|
31
|
+
|
32
|
+
// the follow variables is a long because the time, measured in miliseconds,
|
33
|
+
// will quickly become a bigger number than can be stored in an int.
|
34
|
+
long interval = 1000; // interval at which to blink (milliseconds)
|
35
|
+
|
36
|
+
void setup() {
|
37
|
+
// set the digital pin as output:
|
38
|
+
pinMode(ledPin, OUTPUT);
|
39
|
+
}
|
40
|
+
|
41
|
+
void loop()
|
42
|
+
{
|
43
|
+
// here is where you'd put code that needs to be running all the time.
|
44
|
+
|
45
|
+
// check to see if it's time to blink the LED; that is, if the
|
46
|
+
// difference between the current time and last time you blinked
|
47
|
+
// the LED is bigger than the interval at which you want to
|
48
|
+
// blink the LED.
|
49
|
+
unsigned long currentMillis = millis();
|
50
|
+
|
51
|
+
if(currentMillis - previousMillis > interval) {
|
52
|
+
// save the last time you blinked the LED
|
53
|
+
previousMillis = currentMillis;
|
54
|
+
|
55
|
+
// if the LED is off turn it on and vice-versa:
|
56
|
+
if (ledState == LOW)
|
57
|
+
ledState = HIGH;
|
58
|
+
else
|
59
|
+
ledState = LOW;
|
60
|
+
|
61
|
+
// set the LED with the ledState of the variable:
|
62
|
+
digitalWrite(ledPin, ledState);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
/*
|
2
|
+
Fade
|
3
|
+
|
4
|
+
This example shows how to fade an LED on pin 9
|
5
|
+
using the analogWrite() function.
|
6
|
+
|
7
|
+
This example code is in the public domain.
|
8
|
+
|
9
|
+
*/
|
10
|
+
int brightness = 0; // how bright the LED is
|
11
|
+
int fadeAmount = 5; // how many points to fade the LED by
|
12
|
+
|
13
|
+
void setup() {
|
14
|
+
// declare pin 9 to be an output:
|
15
|
+
pinMode(9, OUTPUT);
|
16
|
+
}
|
17
|
+
|
18
|
+
void loop() {
|
19
|
+
// set the brightness of pin 9:
|
20
|
+
analogWrite(9, brightness);
|
21
|
+
|
22
|
+
// change the brightness for next time through the loop:
|
23
|
+
brightness = brightness + fadeAmount;
|
24
|
+
|
25
|
+
// reverse the direction of the fading at the ends of the fade:
|
26
|
+
if (brightness == 0 || brightness == 255) {
|
27
|
+
fadeAmount = -fadeAmount ;
|
28
|
+
}
|
29
|
+
// wait for 30 milliseconds to see the dimming effect
|
30
|
+
delay(30);
|
31
|
+
}
|