• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* Copyright JS Foundation and other contributors, http://js.foundation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16var led = 0;
17
18// Setting the pin to 0 turns the LED on
19var led_off = 1;
20var led_on = 0;
21
22var digital_outs = [];
23
24var leds = [LED1, LED2, LED3, LED4];
25
26function connect_pins() {
27    print("Creating new DigitalOuts");
28    digital_outs = [];
29    for (var i = 0; i < 4; i++) {
30        digital_outs.push(DigitalOut(leds[i], led_off));
31        if (digital_outs[i].is_connected()) {
32            print("LED " + i + " is connected.");
33        }
34        else {
35            print("LED " + i + " is not connected.");
36        }
37    }
38}
39
40connect_pins();
41
42function blink() {
43    digital_outs[0].write(led_off);
44    digital_outs[1].write(led_off);
45    digital_outs[2].write(led_off);
46    digital_outs[3].write(led_off);
47
48    digital_outs[led].write(led_on);
49
50    print("Finished with LED " + led);
51    led = (led + 1) % 4;
52}
53
54// BUTTON2 on NRF52
55// USER_BUTTON on NUCLEO
56// SW2 on the K64F
57// BTN0 on EFM32GG
58var button;
59
60/* global BUTTON2, SW2, USER_BUTTON, BTN0 */
61if (typeof BUTTON2 !== 'undefined') {
62        button = InterruptIn(BUTTON2);
63} else if (typeof SW2 !== 'undefined') {
64        button = InterruptIn(SW2);
65} else if (typeof USER_BUTTON !== 'undefined') {
66        button = InterruptIn(USER_BUTTON);
67} else if (typeof BTN0 !== 'undefined') {
68        button = InterruptIn(BTN0);
69} else {
70        print("no button specified");
71}
72button.fall(function() {
73    print("YOU PUSHED THE BUTTON!");
74});
75
76print("flash_leds.js has finished executing.");
77