Modifications

Sauter à la navigation Sauter à la recherche
1 823 octets ajoutés ,  21 décembre 2014 à 19:24
Page créée avec « {{Spark.IO-CLI-NAV}} {{traduction}} {{bloc-etroit|text=You can write whole apps and flash them remotely from the command line just as you would from the build IDE. Let's wr... »
{{Spark.IO-CLI-NAV}}

{{traduction}}

{{bloc-etroit|text=You can write whole apps and flash them remotely from the command line just as you would from the build IDE. Let's write a small blink sketch to try it out.

Copy and paste the following program into a file called '''blinky.ino'''}}

<nowiki>#Copy me to blinky.ino
#define PIN D7
int state = 0;

void setup() {
//tell the core we want to write to this pin
pinMode(PIN, OUTPUT);
}
void loop() {
//alternate the PIN between high and low
digitalWrite(PIN, (state) ? HIGH : LOW);

//invert the state
state = !state;

//wait half a second
delay(500);
}</nowiki>

{{bloc-etroit|text=Then let's compile that program to make sure it's valid code. The CLI will automatically download the compiled binary of your program if everything went well, and show you the url. The server will also keep a copy of your binary around for you for about 24 hours.}}

<nowiki># how to compile a program without flashing to your core
$ spark compile blinky.ino
Including:
blinky.ino
attempting to compile firmware
pushing file: blinky.ino
grabbing binary from: https://api.spark.io/v1/binaries/01234567890ABCDEFGH
saved firmware to firmware_123456781234.bin
Compiled firmware downloaded.</nowiki>

Now that we have a valid program, let's flash it to our core! We can use either the source code again, or we can send our binary.

<nowiki># how to flash a program to your core (from source code)
$ spark flash my_core_name blinky.ino</nowiki>

OR - how to flash a pre-compiled binary to your core

<nowiki>$ spark flash my_core_name firmware_123456781234.bin
Including:
firmware_123456781234.bin
attempting to flash firmware to your core my_core_name
flash core said {"id":"01234567890ABCDEFGH","status":"Update started"}</nowiki>

{{Spark.IO-CLI-TRAILER}}
32 920

modifications

Menu de navigation