diff --git a/build/macosx/Arduino.xcodeproj/project.pbxproj b/build/macosx/Arduino.xcodeproj/project.pbxproj index b5a2c1045..bb28e79a1 100644 --- a/build/macosx/Arduino.xcodeproj/project.pbxproj +++ b/build/macosx/Arduino.xcodeproj/project.pbxproj @@ -39,6 +39,7 @@ 33FFFE1D0965BC050016AC38 /* CopyFiles */, 33FF070C0965BF760016AC38 /* CopyFiles */, 33FF07130965BFA80016AC38 /* CopyFiles */, + 336EA3E309FF84FA0052D765 /* CopyFiles */, 33FF071D0965C1C20016AC38 /* CopyFiles */, 33FF07170965BFFE0016AC38 /* ShellScript */, ); @@ -154,6 +155,7 @@ /* Begin PBXBuildFile section */ 330B21540968180400345666 /* librxtxSerial.jnilib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 330B21530968180400345666 /* librxtxSerial.jnilib */; }; 332D4DB609CF147F00BF81F6 /* Sizer.java in Sources */ = {isa = PBXBuildFile; fileRef = 332D4DB509CF147F00BF81F6 /* Sizer.java */; }; + 336EA55B09FF87F60052D765 /* examples in CopyFiles */ = {isa = PBXBuildFile; fileRef = 336EA4DB09FF87E30052D765 /* examples */; }; 339514EE097AEB5900193C89 /* STDCTokenTypes.txt in Resources */ = {isa = PBXBuildFile; fileRef = 33FFFE420965BD110016AC38 /* STDCTokenTypes.txt */; }; 339514FA097AEB8000193C89 /* license.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 33FF02B60965BD170016AC38 /* license.txt */; }; 339514FB097AEB8000193C89 /* readme.txt in CopyFiles */ = {isa = PBXBuildFile; fileRef = 33FF02B70965BD170016AC38 /* readme.txt */; }; @@ -288,6 +290,16 @@ /* End PBXContainerItemProxy section */ /* Begin PBXCopyFilesBuildPhase section */ + 336EA3E309FF84FA0052D765 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 16; + files = ( + 336EA55B09FF87F60052D765 /* examples in CopyFiles */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 33CF03C809662DA200F2C9A9 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; @@ -369,6 +381,7 @@ 330B21530968180400345666 /* librxtxSerial.jnilib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.bundle"; path = librxtxSerial.jnilib; sourceTree = ""; }; 332D4DB509CF147F00BF81F6 /* Sizer.java */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.java; path = Sizer.java; sourceTree = ""; }; 333269E1099BB1FC007D3AE2 /* tools.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = tools.zip; sourceTree = ""; }; + 336EA4DB09FF87E30052D765 /* examples */ = {isa = PBXFileReference; lastKnownFileType = folder; path = examples; sourceTree = ""; }; 337CD3F309EFC183002B890C /* fetch.sh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.script.sh; path = fetch.sh; sourceTree = ""; }; 33AF620A0965D67800B514A9 /* antlr.jar */ = {isa = PBXFileReference; lastKnownFileType = archive.jar; path = antlr.jar; sourceTree = ""; }; 33AF620B0965D67900B514A9 /* applet.html */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text.html; path = applet.html; sourceTree = ""; }; @@ -382,7 +395,6 @@ 33BEE0CD09D7446100430D5B /* Library.java */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.java; path = Library.java; sourceTree = ""; }; 33CF03B009662CA800F2C9A9 /* arduino.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = arduino.icns; path = dist/arduino.icns; sourceTree = ""; }; 33DD8FB6096AC8DA0013AF8F /* Arduino.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Arduino.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 33FF01DC0965BD160016AC38 /* examples.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = examples.zip; sourceTree = ""; }; 33FF01DE0965BD160016AC38 /* about.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = about.jpg; sourceTree = ""; }; 33FF02770965BD160016AC38 /* buttons.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = buttons.gif; sourceTree = ""; }; 33FF02780965BD160016AC38 /* icon.gif */ = {isa = PBXFileReference; lastKnownFileType = image.gif; path = icon.gif; sourceTree = ""; }; @@ -561,7 +573,7 @@ 33FF01DB0965BD160016AC38 /* dist */ = { isa = PBXGroup; children = ( - 33FF01DC0965BD160016AC38 /* examples.zip */, + 336EA4DB09FF87E30052D765 /* examples */, ); path = dist; sourceTree = ""; @@ -1057,18 +1069,16 @@ files = ( ); inputPaths = ( - ../shared/dist/examples.zip, ../shared/reference.zip, dist/tools.zip, ); outputPaths = ( $BUILT_PRODUCTS_DIR/tools, - $BUILT_PRODUCTS_DIR/examples, $BUILT_PRODUCTS_DIR/reference, ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "unzip -od $BUILT_PRODUCTS_DIR/examples ../shared/dist/examples.zip\nunzip -od $BUILT_PRODUCTS_DIR ../shared/reference.zip\nunzip -od $BUILT_PRODUCTS_DIR dist/tools.zip"; + shellScript = "unzip -od $BUILT_PRODUCTS_DIR ../shared/reference.zip\nunzip -od $BUILT_PRODUCTS_DIR dist/tools.zip"; }; /* End PBXShellScriptBuildPhase section */ diff --git a/build/macosx/make.sh b/build/macosx/make.sh index 41b5cbba6..86091e1d4 100755 --- a/build/macosx/make.sh +++ b/build/macosx/make.sh @@ -23,7 +23,7 @@ else mkdir -p work/classes/processing/app/syntax mkdir -p work/classes/processing/app/tools mkdir -p work/lib/build - mkdir -p work/examples + #mkdir -p work/examples cp dist/librxtxSerial.jnilib work/ cp -pR dist/drivers work/ @@ -34,8 +34,9 @@ else # cvs doesn't seem to want to honor the +x bit chmod +x work/Arduino.app/Contents/MacOS/JavaApplicationStub - echo Extracting examples... - unzip -d work/examples ../shared/dist/examples.zip + #echo Extracting examples... + #unzip -d work/examples ../shared/dist/examples.zip + cp -pR ../shared/ # copy the avr-gcc distribution echo Copying tools \(this may take a minute\)... diff --git a/build/shared/dist/examples.zip b/build/shared/dist/examples.zip deleted file mode 100644 index 95f8758c7..000000000 Binary files a/build/shared/dist/examples.zip and /dev/null differ diff --git a/build/shared/dist/examples/digital IO/digital_read/digital_read.pde b/build/shared/dist/examples/digital IO/digital_read/digital_read.pde new file mode 100644 index 000000000..8f15d5326 --- /dev/null +++ b/build/shared/dist/examples/digital IO/digital_read/digital_read.pde @@ -0,0 +1,31 @@ +/* Basic Digital Read + * ------------------ + * + * turns on and off a light emitting diode(LED) connected to digital + * pin 13, when pressing a pushbutton attached to pin 7. It illustrates the + * concept of Active-Low, which consists in connecting buttons using a + * 1K to 10K pull-up resistor. + * + * Created 1 December 2005 + * copyleft 2005 DojoDave + * http://arduino.berlios.de + * + */ + +int ledPin = 13; // choose the pin for the LED +int inPin = 7; // choose the input pin (for a pushbutton) +int val = 0; // variable for reading the pin status + +void setup() { + pinMode(ledPin, OUTPUT); // declare LED as output + pinMode(inPin, INPUT); // declare pushbutton as input +} + +void loop(){ + val = digitalRead(inPin); // read input value + if (val == HIGH) { // check if the input is HIGH (button released) + digitalWrite(ledPin, LOW); // turn LED OFF + } else { + digitalWrite(ledPin, HIGH); // turn LED ON + } +} diff --git a/build/shared/dist/examples/digital IO/digital_read_and_blink/digital_read_and_blink.pde b/build/shared/dist/examples/digital IO/digital_read_and_blink/digital_read_and_blink.pde new file mode 100644 index 000000000..6d4dfc0e2 --- /dev/null +++ b/build/shared/dist/examples/digital IO/digital_read_and_blink/digital_read_and_blink.pde @@ -0,0 +1,24 @@ +/* Blink when Digital Read + * ------------------------ + */ + +int ledPin = 13; // choose the pin for the LED +int inPin = 7; // choose the input pin (for a pushbutton) +int val = 0; // variable for reading the pin status + +void setup() { + pinMode(ledPin, OUTPUT); // declare LED as output + pinMode(inPin, INPUT); // declare pushbutton as input +} + +void loop(){ + val = digitalRead(inPin); // read input value + if (val == HIGH) { // check if the input is HIGH (button released) + digitalWrite(ledPin, LOW); // turn LED OFF + } else { + digitalWrite(ledPin, HIGH); // blink the LED and go OFF + delay(200); + digitalWrite(ledPin, LOW); + delay(1000); + } +} diff --git a/build/shared/dist/examples/lcd/lcd_8bits/lcd_8bits.pde b/build/shared/dist/examples/lcd/lcd_8bits/lcd_8bits.pde new file mode 100644 index 000000000..0232c017c --- /dev/null +++ b/build/shared/dist/examples/lcd/lcd_8bits/lcd_8bits.pde @@ -0,0 +1,110 @@ +/* LCD 8bits + * --------- + * + * This is the first example in how to use an LCD screen + * configured with data transfers over 8 bits. The example + * uses all the digital pins on the Arduino board, but can + * easily display data on the display + * + * There are the following pins to be considered: + * + * - DI, RW, DB0..DB7, Enable (11 in total) + * + * the pinout for LCD displays is standard and there is plenty + * of documentation to be found on the internet. + * + * Picture at: + * http://arduino.berlios.de/index.php/Tutorial/LCD8Bits + * + * (cleft) 2005 DojoDave for K3 + * + */ + +int DI = 12; +int RW = 11; +int DB[] = {3, 4, 5, 6, 7, 8, 9, 10}; +int Enable = 2; + +void LcdCommandWrite(int value) { + // poll all the pins + int i = 0; + for (i=DB[0]; i <= DI; i++) { + digitalWrite(i,value & 01); + value >>= 1; + } + digitalWrite(Enable,LOW); + delayMicroseconds(1); + // send a pulse to enable + digitalWrite(Enable,HIGH); + delayMicroseconds(1); // pause 1 ms according to datasheet + digitalWrite(Enable,LOW); + delayMicroseconds(1); // pause 1 ms according to datasheet +} + +void LcdDataWrite(int value) { + // poll all the pins + int i = 0; + digitalWrite(DI, HIGH); + digitalWrite(RW, LOW); + for (i=DB[0]; i <= DB[7]; i++) { + digitalWrite(i,value & 01); + value >>= 1; + } + digitalWrite(Enable,LOW); + delayMicroseconds(1); + // send a pulse to enable + digitalWrite(Enable,HIGH); + delayMicroseconds(1); + digitalWrite(Enable,LOW); + delayMicroseconds(1); // pause 1 ms according to datasheet +} + +void setup (void) { + int i = 0; + for (i=Enable; i <= DI; i++) { + pinMode(i,OUTPUT); + } + delay(100); + // initiatize lcd after a short pause + // needed by the LCDs controller + LcdCommandWrite(0x30); // function set: + // 8-bit interface, 1 display lines, 5x7 font + delay(64); + LcdCommandWrite(0x30); // function set: + // 8-bit interface, 1 display lines, 5x7 font + delay(50); + LcdCommandWrite(0x30); // function set: + // 8-bit interface, 1 display lines, 5x7 font + delay(20); + LcdCommandWrite(0x06); // entry mode set: + // increment automatically, no display shift + delay(20); + LcdCommandWrite(0x0E); // display control: + // turn display on, cursor on, no blinking + delay(20); + LcdCommandWrite(0x01); // clear display, set cursor position to zero + delay(100); + LcdCommandWrite(0x80); // display control: + // turn display on, cursor on, no blinking + delay(20); +} + +void loop (void) { + LcdCommandWrite(0x02); // set cursor position to zero + delay(10); + // Write the welcome message + LcdDataWrite('H'); + LcdDataWrite('o'); + LcdDataWrite('l'); + LcdDataWrite('a'); + LcdDataWrite(' '); + LcdDataWrite('C'); + LcdDataWrite('a'); + LcdDataWrite('r'); + LcdDataWrite('a'); + LcdDataWrite('c'); + LcdDataWrite('o'); + LcdDataWrite('l'); + LcdDataWrite('a'); + delay(500); +} diff --git a/build/shared/dist/examples/led_blink/led_blink.pde b/build/shared/dist/examples/led_blink/led_blink.pde new file mode 100644 index 000000000..afeed87d7 --- /dev/null +++ b/build/shared/dist/examples/led_blink/led_blink.pde @@ -0,0 +1,28 @@ +/* Blinking LED + * ------------ + * + * turns on and off a light emitting diode(LED) connected to a digital + * pin, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino + * board because it has a resistor attached to it, needing only an LED + * + * Created 1 June 2005 + * copyleft 2005 DojoDave + * http://arduino.berlios.de + * + * based on an orginal by H. Barragan for the Wiring i/o board + */ + +int ledPin = 13; // LED connected to digital pin 13 + +void setup() +{ + pinMode(ledPin, OUTPUT); // sets the digital pin as output +} + +void loop() +{ + digitalWrite(ledPin, HIGH); // sets the LED on + delay(1000); // waits for a second + digitalWrite(ledPin, LOW); // sets the LED off + delay(1000); // waits for a second +} diff --git a/build/shared/dist/examples/leds/knight_rider/knight_rider_1/knight_rider_1.pde b/build/shared/dist/examples/leds/knight_rider/knight_rider_1/knight_rider_1.pde new file mode 100644 index 000000000..d99c5847a --- /dev/null +++ b/build/shared/dist/examples/leds/knight_rider/knight_rider_1/knight_rider_1.pde @@ -0,0 +1,86 @@ +/* Knight Rider 1 + * -------------- + * + * Knight Rider is an AI car that showed up in the TV series from + * the 80's with David Hasselhoff. The car had plenty of LED effects. + * + * Basically this is an extension of Blink_LED. This program handles + * 6 LEDs connected to pins 2 to 7. This is the first of a series of + * three examples useful to understand the for(;;) loop + * + * Picture at: + * http://arduino.berlios.de/index.php/Tutorial/KnightRider + * + * (cleft) 2005 K3, Malmo University + * @author: David Cuartielles + * @hardware: David Cuartielles, Aaron Hallborg + */ + +int pin2 = 2; +int pin3 = 3; +int pin4 = 4; +int pin5 = 5; +int pin6 = 6; +int pin7 = 7; +int timer = 100; + +void setup(){ + pinMode(pin2, OUTPUT); + pinMode(pin3, OUTPUT); + pinMode(pin4, OUTPUT); + pinMode(pin5, OUTPUT); + pinMode(pin6, OUTPUT); + pinMode(pin7, OUTPUT); +} + +void loop() { + digitalWrite(pin2, HIGH); + delay(timer); + digitalWrite(pin2, LOW); + delay(timer); + + digitalWrite(pin3, HIGH); + delay(timer); + digitalWrite(pin3, LOW); + delay(timer); + + digitalWrite(pin4, HIGH); + delay(timer); + digitalWrite(pin4, LOW); + delay(timer); + + digitalWrite(pin5, HIGH); + delay(timer); + digitalWrite(pin5, LOW); + delay(timer); + + digitalWrite(pin6, HIGH); + delay(timer); + digitalWrite(pin6, LOW); + delay(timer); + + digitalWrite(pin7, HIGH); + delay(timer); + digitalWrite(pin7, LOW); + delay(timer); + + digitalWrite(pin6, HIGH); + delay(timer); + digitalWrite(pin6, LOW); + delay(timer); + + digitalWrite(pin5, HIGH); + delay(timer); + digitalWrite(pin5, LOW); + delay(timer); + + digitalWrite(pin4, HIGH); + delay(timer); + digitalWrite(pin4, LOW); + delay(timer); + + digitalWrite(pin3, HIGH); + delay(timer); + digitalWrite(pin3, LOW); + delay(timer); +} diff --git a/build/shared/dist/examples/leds/knight_rider/knight_rider_2/knight_rider_2.pde b/build/shared/dist/examples/leds/knight_rider/knight_rider_2/knight_rider_2.pde new file mode 100644 index 000000000..ef1cf1025 --- /dev/null +++ b/build/shared/dist/examples/leds/knight_rider/knight_rider_2/knight_rider_2.pde @@ -0,0 +1,46 @@ +/* Knight Rider 2 + * -------------- + * + * Knight Rider is an AI car that showed up in the TV series from + * the 80's with David Hasselhoff. The car had plenty of LED effects. + * + * Basically this is an extension of Blink_LED. This program handles + * 6 LEDs connected to pins 2 to 7. This is the second of a series of + * three examples useful to understand the for(;;) loop + * + * In this example we declare an array with the pin numbers we use as inputs, + * then we browse the array up and down to turn the different pins on/off + * + * Picture at: + * http://arduino.berlios.de/index.php/Tutorial/KnightRider + * + * (cleft) 2005 K3, Malmo University + * @author: David Cuartielles + * @hardware: David Cuartielles, Aaron Hallborg + */ + +int pinArray[] = {2, 3, 4, 5, 6, 7}; +int count = 0; +int timer = 100; + +void setup(){ + // we make all the declarations at once + for (count=0;count<6;count++) { + pinMode(pinArray[count], OUTPUT); + } +} + +void loop() { + for (count=0;count<6;count++) { + digitalWrite(pinArray[count], HIGH); + delay(timer); + digitalWrite(pinArray[count], LOW); + delay(timer); + } + for (count=5;count>=0;count--) { + digitalWrite(pinArray[count], HIGH); + delay(timer); + digitalWrite(pinArray[count], LOW); + delay(timer); + } +} diff --git a/build/shared/dist/examples/leds/knight_rider/knight_rider_3/knight_rider_3.pde b/build/shared/dist/examples/leds/knight_rider/knight_rider_3/knight_rider_3.pde new file mode 100644 index 000000000..35edadac2 --- /dev/null +++ b/build/shared/dist/examples/leds/knight_rider/knight_rider_3/knight_rider_3.pde @@ -0,0 +1,51 @@ +/* Knight Rider 3 + * -------------- + * + * Knight Rider is an AI car that showed up in the TV series from + * the 80's with David Hasselhoff. The car had plenty of LED effects. + * + * Basically this is an extension of Blink_LED. This program handles + * 6 LEDs connected to pins 2 to 7. This is the third of a series of + * three examples useful to understand the for(;;) loop + * + * In this example we declare an array with the pin numbers we use as inputs, + * then we browse the array up and down to turn the different pins on/off + * + * This example concentrates in making the visuals fluid. + * + * Picture at: + * http://arduino.berlios.de/index.php/Tutorial/KnightRider + * + * (cleft) 2005 K3, Malmo University + * @author: David Cuartielles + * @hardware: David Cuartielles, Aaron Hallborg + */ + +int pinArray[] = {2, 3, 4, 5, 6, 7}; +int count = 0; +int timer = 30; + +void setup(){ + for (count=0;count<6;count++) { + pinMode(pinArray[count], OUTPUT); + } +} + +void loop() { + for (count=0;count<5;count++) { + digitalWrite(pinArray[count], HIGH); + delay(timer); + digitalWrite(pinArray[count + 1], HIGH); + delay(timer); + digitalWrite(pinArray[count], LOW); + delay(timer*2); + } + for (count=5;count>0;count--) { + digitalWrite(pinArray[count], HIGH); + delay(timer); + digitalWrite(pinArray[count - 1], HIGH); + delay(timer); + digitalWrite(pinArray[count], LOW); + delay(timer*2); + } +} diff --git a/build/shared/dist/examples/leds/led_drivers/max7219_v1/max7219_v1.pde b/build/shared/dist/examples/leds/led_drivers/max7219_v1/max7219_v1.pde new file mode 100644 index 000000000..6abfd3427 --- /dev/null +++ b/build/shared/dist/examples/leds/led_drivers/max7219_v1/max7219_v1.pde @@ -0,0 +1,194 @@ +int serialVal = 0; +int value = 0; +int i = 0; +boolean reading = false; +boolean writing = false; +int times = 0; +int serialBuff[7]; + +// define wiring pins +byte pin_max7219_clock = 4; +byte pin_max7219_load = 2; +byte pin_max7219_dataIn = 3; + +// specify wiring pin i/o directions +void setPinModes() +{ + pinMode(pin_max7219_dataIn, OUTPUT); + pinMode(pin_max7219_clock, OUTPUT); + pinMode(pin_max7219_load, OUTPUT); +} + +// define max7219 registers +byte max7219_reg_noop = 0x00; +byte max7219_reg_digit0 = 0x01; +byte max7219_reg_digit1 = 0x02; +byte max7219_reg_digit2 = 0x03; +byte max7219_reg_digit3 = 0x04; +byte max7219_reg_digit4 = 0x05; +byte max7219_reg_digit5 = 0x06; +byte max7219_reg_digit6 = 0x07; +byte max7219_reg_digit7 = 0x08; +byte max7219_reg_decodeMode = 0x09; +byte max7219_reg_intensity = 0x0a; +byte max7219_reg_scanLimit = 0x0b; +byte max7219_reg_shutdown = 0x0c; +byte max7219_reg_displayTest = 0x0f; + +// define max7219 as rows and cols (for nexus 8x8 displays) +byte max7219_row0 = 0x01; +byte max7219_row1 = 0x02; +byte max7219_row2 = 0x03; +byte max7219_row3 = 0x04; +byte max7219_row4 = 0x05; +byte max7219_row5 = 0x06; +byte max7219_row6 = 0x07; +byte max7219_row7 = 0x08; +byte max7219_col0 = 0x80; +byte max7219_col1 = 0x01; +byte max7219_col2 = 0x02; +byte max7219_col3 = 0x04; +byte max7219_col4 = 0x08; +byte max7219_col5 = 0x10; +byte max7219_col6 = 0x20; +byte max7219_col7 = 0x40; + + +// function to control max7219 data line +void max7219_setData(boolean value) +{ + digitalWrite(pin_max7219_dataIn, value); +} + +// function to control max7219 clock line +void max7219_setClock(boolean value) +{ + digitalWrite(pin_max7219_clock, value); +} + +// function to control max7219 load line +void max7219_setLoad(boolean value) +{ + digitalWrite(pin_max7219_load, value); +} + +// function that puts a byte of data to the max7219 +void max7219_putByte(byte data) +{ + byte i = 8; + byte mask; + while(i > 0) { + mask = 0x01 << (i - 1); // get bitmask + max7219_setClock(LOW); // tick + if (data & mask){ // choose bit + max7219_setData(HIGH); // send 1 + }else{ + max7219_setData(LOW); // send 0 + } + max7219_setClock(HIGH); // tock + --i; // move to lesser bit + } +} + +// function that puts a byte of data into a max7219 register +void max7219_put(byte reg, byte data) +{ + max7219_setLoad(HIGH); // begin + max7219_putByte(reg); // specify register + max7219_putByte(data); // put data + max7219_setLoad(LOW); // latch in data + max7219_setLoad(HIGH); // end +} + +// function that sets brightness of the max7219 +void max7219_setIntensity(byte intensity) +{ + // range: 0x00 to 0x0f + max7219_put(max7219_reg_intensity, intensity & 0x0f); +} +//////////////////////////////////////////// +// function that sets the same value for all registers of the max7219 + +void max7219_all(byte value) +{ + max7219_put(0x01, value); + max7219_put(0x02, value); + max7219_put(0x03, value); + max7219_put(0x04, value); + max7219_put(0x05, value); + max7219_put(0x06, value); + max7219_put(0x07, value); + max7219_put(0x08, value); +} + +/////////////////////////////////////////// +void printBuff(){ + for (i=1;i <= 8;i++){ + max7219_put(0x0+i, serialBuff[i-1]); + } +} +//////////////////////////////////////////// + +void readBuff(){ + printString("into readbuff method"); + serialVal = serialRead(); + if (serialVal != -1){ + printString("information there"); + if ((serialVal == 43) && !reading){ + reading = true; + printString("plus"); + } + + if ((serialVal == 45) && (times == 0 && reading)){ + writing = true; + printString("minus"); + } + + if (reading && writing){ + serialBuff[times] = serialVal; + times++; + } + + if (times >= 7){ + printString("Print to buff"); + times = 0; + reading = false; + writing = false; + printBuff(); + } + + + } +} + +////////////////////////////////////////////////////////////// + +// function that initializes the max7219 to use a matrix of leds +void max7219_init() +{ + max7219_put(max7219_reg_scanLimit, 0x07); // use all 8 columns + max7219_put(max7219_reg_decodeMode, 0x00); // using an led matrix (not digits) + max7219_put(max7219_reg_shutdown, 0x01); // not in shutdown mode + max7219_put(max7219_reg_displayTest, 0x00); // no display test + max7219_all(0x00); // empty registers + max7219_setIntensity(0x0f); // set initial brightness to dim +} + + + +// program initialization routine +void setup() +{ + setPinModes(); + max7219_init(); +} + +// program loop +void loop() +{ + printString("in the loop"); + //max7219_all(0x00); + //delay(500); + readBuff(); + +} diff --git a/build/shared/dist/examples/leds/led_drivers/shift_out/shift_out.pde b/build/shared/dist/examples/leds/led_drivers/shift_out/shift_out.pde new file mode 100644 index 000000000..5ad50bec2 --- /dev/null +++ b/build/shared/dist/examples/leds/led_drivers/shift_out/shift_out.pde @@ -0,0 +1,79 @@ +/* Shift Out + * --------- + * + * This example uses the LED driver 4794 from Philips to drive + * 8 LEDs at once. The 4794 is a chip that can be chained so that + * we will be able of adding 8 outputs each time you add a new chip + * + * We use four pins to connect to the chip: + * + * - data: this one sends the data out to the chip + * + * - strob: controls the load of data to the chip's output + * + * - clock: synchronizes the load of data + * + * - oe: turns the output on/off, we use it to control the luminosity of the LEDs + * + * Pictures at: + * http://arduino.berlios.de/index.php/Tutorial/LEDDriver + * + * (copyleft) 2005 K3, Malmo University + * @author: David Cuartielles, Marcus Hannerstig + * @hardware: David Cuartielles, Marcos Yarza + * @project: SMEE - Experiential Vehicles + * + */ + + +int data = 9; +int strob = 8; +int clock = 10; +int oe = 11; +int count = 0; +int dato = 0; // dato is a varible we use to send data to the LEDs + +void setup() +{ + //beginSerial(9600); // uncomment the serial-related lines to monitor the program's progress + pinMode(data, OUTPUT); // declare all the control pins as outputs + pinMode(clock, OUTPUT); + pinMode(strob, OUTPUT); + pinMode(oe, OUTPUT); +} + + +// sends a pulse to the 4794 indicating that +// it is time to load data +void PulseClock(void) { + digitalWrite(clock, LOW); + delayMicroseconds(20); + digitalWrite(clock, HIGH); + delayMicroseconds(50); + digitalWrite(clock, LOW); +} + +void loop() +{ + dato = 129; // if dato equals 129 the first and last LED will be on + + // go through the "dato" variable and send it bit by bit over the data pin + for (count = 0; count < 8; count++) { + digitalWrite(data, dato & 01); + //serialWrite((dato & 01) + 48); + dato>>=1; + if (count == 7){ + digitalWrite(oe, LOW); + digitalWrite(strob, HIGH); + } + PulseClock(); + digitalWrite(oe, HIGH); + } + + delayMicroseconds(20); + digitalWrite(strob, LOW); + delay(100); + + //printNewline(); + delay(100); // waits for a second +} diff --git a/build/shared/dist/examples/motors/dc_motor/dc_motor.pde b/build/shared/dist/examples/motors/dc_motor/dc_motor.pde new file mode 100644 index 000000000..ed7b10498 --- /dev/null +++ b/build/shared/dist/examples/motors/dc_motor/dc_motor.pde @@ -0,0 +1,36 @@ +/* DC motor + * -------- + * + * Switch a motor on and off making use of a transistor + * we use of a BD137 from Fairchild. It is possible to + * play with the motor's innertia, and use a potentiometer to + * control the speed. + * + * (cleft) 2005 DojoDave for DojoCorp at Madrid Medialab - Spain + */ + +int motorPin = 6; // selec the pin where the motor is connected at +int value = 0; // variable to store the reading from the potentiometer +int potPin = 0; // analog pin where to plug the potentiometer at + +void setup() { + pinMode(motorPin, OUTPUT); // declare the motor as an output + beginSerial(9600); // connect to the serial port to send values back +} + +void loop() { + // read the potentiometer + value = analogRead(potPin); + + // print its value back to the computer + printInteger(value); + printNewline(); + + // turn the motor on + digitalWrite(motorPin,HIGH); + delay(50); + digitalWrite(motorPin,LOW); + + // this will control how long the motor is off + delay(value); +} diff --git a/build/shared/dist/examples/motors/dc_two_motors/dc_two_motors.pde b/build/shared/dist/examples/motors/dc_two_motors/dc_two_motors.pde new file mode 100644 index 000000000..9393808f5 --- /dev/null +++ b/build/shared/dist/examples/motors/dc_two_motors/dc_two_motors.pde @@ -0,0 +1,121 @@ +/* Driving two DC motors + * ----------------------- + * + * Custom timer originally intended to DC motor + * control purposes and made from two nested loops: + * - "scan cycle" is the main loop + * - "control cycle" is the internal loop + * Timing id adjusted by changing number of iterations en each loop + * and the internal delay of each control cycle iteration (tic). If scan + * cycle code takes significative time to jam current control cycle, this + * delay could be easily reduced or bypassed. + * + * (copyleft) 2005 by Quique + * + * posted to the Arduino Forum + * + * + */ + + int ledPin0 = 13; // LED connected to digital pin 13 + int motorPin1 = 9; // Motor 1 connected to digital pin 9 + int motorPin2 = 8; // Motor 1 connected to digital pin 8 + + int potPin1 = 5; // Potentiometer1 connected to analog pin 5 ( 5 is 1 in some boards) + int potPin2 = 4; // Potentiometer1 connected to analog pin 5 ( 4 is 2 in some boards) + +// Timing Setup + + int scanCycle = 10; // Number of control cycles in a scan cycle + int controlCycle = 200; // Control cycle iterations + int tic = 6; // Control cycle iteration aditional delay in microseconds + + int currentSCycle = 0; // Current scan cycle iteration + int currentCCycle = 0; // Current control cycle iteration + boolean scanEnable = true; // Allows read analog & digital inputs + +// End timing setup + + int counter = 0; // Scan cycle counter used to change led status + int motor1_PW; // motor 1 Pulse Width + int motor2_PW; // motor 2 Pulse Width + +/* +* Switch the boolean value assigned to any variable +*/ +boolean boolSwitch (boolean *target) +{ + if ( *target ) {*target = false;} else { *target = true; } + return *target; +} + +void setup() +{ + pinMode (ledPin0, OUTPUT); // sets the digital pin as output + pinMode (motorPin1, OUTPUT); // sets the digital pin as output + pinMode (motorPin2, OUTPUT); // sets the digital pin as output +} + +void loop() +{ +// Scan cycle + + if (scanEnable) + { + // + // Scan cycle logic here + // + motor1_PW = analogRead (potPin1)/5; // Pot 1 read scale change + motor2_PW = analogRead (potPin2)/5; // Pot 1 read scale change + + // Swith led in pin 13 each 10 scan cycles. We can assume that while + // Led is on (or off), porgram has taken 10 scan cycles. So, if we adjust + // blink time to 1 sec, we are able to scanning inputs each 100 msec. + if (counter++ >= 10) + { + digitalWrite (ledPin0, boolSwitch (ledPin0)); // Led blink each 10 scan cycles i.e. if + // led is on 1 second, we are scaning knobs each + // 100 miliseconds + counter =0; + } + } + +// Control cycle + for (currentCCycle = 0; currentCCycle < controlCycle; currentCCycle ++) + { + delayMicroseconds (tic); + // + // Control cycle logic here + // + if ( motor1_PW > currentCCycle ) + { + digitalWrite ( motorPin1, LOW); + } + else + { + digitalWrite ( motorPin1, HIGH); + } + + if ( motor2_PW > currentCCycle ) + { + digitalWrite ( motorPin2, LOW); + } + else + { + digitalWrite ( motorPin2, HIGH); + } + + } + +// Detect completed scan cycle + if ( currentSCycle ++ > scanCycle) + { + scanEnable = true; // Allow readings of external inputs + currentSCycle = 0; // Reset scan cycle counter + } + else + { + scanEnable = false; // + } +} + diff --git a/build/shared/dist/examples/motors/stepper_unipolar/stepper_unipolar.pde b/build/shared/dist/examples/motors/stepper_unipolar/stepper_unipolar.pde new file mode 100644 index 000000000..416647aab --- /dev/null +++ b/build/shared/dist/examples/motors/stepper_unipolar/stepper_unipolar.pde @@ -0,0 +1,57 @@ +/* Stepper Copal Unipolar + * ---------------------- + * + * Program to drive a stepper motor coming from a 5'25 disk drive + * according to the documentation I found, this stepper: "[...] motor + * made by Copal Electronics, with 1.8 degrees per step and 96 ohms + * per winding, with center taps brought out to separate leads [...]" + * [http://www.cs.uiowa.edu/~jones/step/example.html] + * + * It is a bipolar stepper motor with 5 wires: + * + * - red: power connector, I have it at 5V and works fine + * - orange and black: coil 1 + * - brown and yellow: coil 2 + * + * (cleft) 2005 DojoDave for K3 + * http://www.0j0.org | http://arduino.berlios.de + * + * @author: David Cuartielles + * @date: 20 Oct. 2005 + */ + +int motorPin1 = 8; +int motorPin2 = 9; +int motorPin3 = 10; +int motorPin4 = 11; +int delayTime = 500; + +void setup() { + pinMode(motorPin1, OUTPUT); + pinMode(motorPin2, OUTPUT); + pinMode(motorPin3, OUTPUT); + pinMode(motorPin4, OUTPUT); +} + +void loop() { + digitalWrite(motorPin1, HIGH); + digitalWrite(motorPin2, LOW); + digitalWrite(motorPin3, LOW); + digitalWrite(motorPin4, LOW); + delay(delayTime); + digitalWrite(motorPin1, LOW); + digitalWrite(motorPin2, HIGH); + digitalWrite(motorPin3, LOW); + digitalWrite(motorPin4, LOW); + delay(delayTime); + digitalWrite(motorPin1, LOW); + digitalWrite(motorPin2, LOW); + digitalWrite(motorPin3, HIGH); + digitalWrite(motorPin4, LOW); + delay(delayTime); + digitalWrite(motorPin1, LOW); + digitalWrite(motorPin2, LOW); + digitalWrite(motorPin3, LOW); + digitalWrite(motorPin4, HIGH); + delay(delayTime); +} diff --git a/build/shared/dist/examples/motors/stepper_unipolar_advanced/stepper_unipolar_advanced.pde b/build/shared/dist/examples/motors/stepper_unipolar_advanced/stepper_unipolar_advanced.pde new file mode 100644 index 000000000..f46fe8e1d --- /dev/null +++ b/build/shared/dist/examples/motors/stepper_unipolar_advanced/stepper_unipolar_advanced.pde @@ -0,0 +1,73 @@ +/* Stepper Unipolar Advanced + * ------------------------- + * + * Program to drive a stepper motor coming from a 5'25 disk drive + * according to the documentation I found, this stepper: "[...] motor + * made by Copal Electronics, with 1.8 degrees per step and 96 ohms + * per winding, with center taps brought out to separate leads [...]" + * [http://www.cs.uiowa.edu/~jones/step/example.html] + * + * It is a bipolar stepper motor with 5 wires: + * + * - red: power connector, I have it at 5V and works fine + * - brown and black: coil 1 + * - orange and yellow: coil 2 + * + * We use a potentiometer to control the speed and direction of the motor + * + * (cleft) 2005 DojoDave for K3 + * http://www.0j0.org | http://arduino.berlios.de + * + * @author: David Cuartielles + * @date: 20 Oct. 2005 + */ + +int ledPin = 13; +int statusLed = LOW; +int motorPins[] = {8, 9, 10, 11}; +int count = 0; +int count2 = 0; +int delayTime = 500; +int val = 0; + +void setup() { + pinMode(ledPin, OUTPUT); + for (count = 0; count < 4; count++) { + pinMode(motorPins[count], OUTPUT); + } +} + +void moveForward() { + if ((count2 == 0) || (count2 == 1)) { + count2 = 16; + } + count2>>=1; + for (count = 3; count >= 0; count--) { + digitalWrite(motorPins[count], count2>>count&0x01); + } + delay(delayTime); +} + +void moveBackward() { + if ((count2 == 0) || (count2 == 1)) { + count2 = 16; + } + count2>>=1; + for (count = 3; count >= 0; count--) { + digitalWrite(motorPins[3 - count], count2>>count&0x01); + } + delay(delayTime); +} + +void loop() { + val = analogRead(0); + if (val > 540) { + delayTime = 2048 - 1024 * val / 512 + 1; // move faster the higher the value from the potentiometer + moveForward(); + } else if (val < 480) { + delayTime = 1024 * val / 512 + 1; // move faster the lower the value from the potentiometer + moveBackward(); + } else { + delayTime = 1024; + } +} diff --git a/build/shared/dist/examples/processing/processing_send_potentiometer/processing_send_potentiometer.pde b/build/shared/dist/examples/processing/processing_send_potentiometer/processing_send_potentiometer.pde new file mode 100644 index 000000000..86837ee02 --- /dev/null +++ b/build/shared/dist/examples/processing/processing_send_potentiometer/processing_send_potentiometer.pde @@ -0,0 +1,42 @@ +/* Potentiometer to Processing + * --------------------------- + * + * This program sends data from a potentiometer to Processing + * over the serial port (works in PC: Windows and Linux, and MAC) + * The code reads a potentiometer plugged to an analog + * input and sends the data as a byte back to the computer. + * + * In order to make the data transfer as simple as possible + * we will only send a byte back to the computer, what means + * that the data coming from the ADC will be divided by 4. + * + * (cleft) 2005 DojoDave for K3 + * + * @author: David Cuartielles + * @context: ID3 - K3 - MAH - Sweden + */ + +int ledPin = 13; // pin for the LED +int potPin = 0; // analog pin for the potentiometer +int ledStatus = LOW; // we use a variable to toggle the LEDs state +int val = 0; // variable to store the potentiometer's reading + +void setup() { + pinMode(ledPin, OUTPUT); // declare the ledPin as an output + Serial.begin(9600); // initialize the serial port +} + +void loop() { + // read the potentiometer's value and store it + val = analogRead(potPin)/4; + + // send the value over the port + Serial.print(val, BYTE); + + // wait a bit + delay(100); + + // change the state of the LED (if HIGH, then LOW, and viceversa) + ledStatus = !ledStatus; + digitalWrite(ledPin, ledStatus); +} diff --git a/build/shared/dist/examples/program_template/program_template.pde b/build/shared/dist/examples/program_template/program_template.pde new file mode 100644 index 000000000..ae63dff23 --- /dev/null +++ b/build/shared/dist/examples/program_template/program_template.pde @@ -0,0 +1,29 @@ +/* PROGRAM'S TITLE + * --------------- + * + * Comments + * + * (copyright notice) 2005 by NAME + * + * + * + */ + +// variable declaration +// type name_of_var = value; + +// function declaration +// type name_of_function(type parameters) { +// code_block; +// } + +void setup(void) { + // initialize inputs/outputs + // start serial port +} + +void loop(void) { + // program here + // code_block; +} + diff --git a/build/shared/dist/examples/puredata/PD_inputs_to_PD/PD_inputs_to_PD.pde b/build/shared/dist/examples/puredata/PD_inputs_to_PD/PD_inputs_to_PD.pde new file mode 100644 index 000000000..7444c5b6c --- /dev/null +++ b/build/shared/dist/examples/puredata/PD_inputs_to_PD/PD_inputs_to_PD.pde @@ -0,0 +1,71 @@ +/* Inputs to PD + * ------------------- + * + * This program sends data from a bunch of inputs to PD + * over the serial port (works on PC: Windows and Linux, and MAC) + * The code reads 3 potentiometers and 6 buttons plugged to Arduino + * input and sends the data back to the computer. + * + * On the other side there will be a PureData sketch running + * comport2000 and will use the data to change a sound or video + * file properties. + * + * The buttons will be characterized with '1' or '0' depending on + * their state, while potentiometers will be characterized with a + * 10 bits integer in the range 0..1024 + * + * The first sensor will be marked with 'A' (ascii 65), the second + * with 'B', and so on. The end of sensor reading is marked with + * the characters EOLN (ascii 10). + * + * (cleft) 2005 DojoDave for K3 + * + * @author: David Cuartielles + * @context: ID3 - K3 - MAH - Sweden + */ + +int ledPin = 13; // declare the pin with the LED +int potentioMeter = 0; // declare the analog pin for the potentiometer +int pushButton = 0; // declare the value +int writeChar = 65; // declare the first reading as 'A' +int value = 0; // value to read the different sensors +int ledStatus = LOW; // status of the LED + +void setup() { + pinMode(ledPin, OUTPUT); // declare the LED as output + Serial.begin(9600); // intitialize the serial port +} + +void loop() { + + writeChar = 65; //Sets the sensor idendifier + // character back to 'A'. + + // start reading the potentiometers on the analog pins + for(potentioMeter=0;potentioMeter<3;potentioMeter++){ + Serial.print(writeChar, BYTE); + Serial.print(analogRead(potentioMeter)); + Serial.println(); + writeChar = writeChar + 1; + delay(10); + } + + // read the pushbuttons + for(pushButton=2;pushButton<8;pushButton++){ + Serial.print(writeChar, BYTE); + value = digitalRead(pushButton); // reads the value at a digital input + if (value) + { + Serial.print('0'); + } else { + Serial.print('1'); + } + Serial.println(); + writeChar = writeChar + 1; + delay(10); + } + + delay(100); + ledStatus = !ledStatus; + digitalWrite(ledPin, ledStatus); +} diff --git a/build/shared/dist/examples/puredata/PD_send_potentiometer/PD_send_potentiometer.pde b/build/shared/dist/examples/puredata/PD_send_potentiometer/PD_send_potentiometer.pde new file mode 100644 index 000000000..7740c7aac --- /dev/null +++ b/build/shared/dist/examples/puredata/PD_send_potentiometer/PD_send_potentiometer.pde @@ -0,0 +1,37 @@ +/* Potentiometer to PD + * ------------------- + * + * This program sends data from a potentiometer to PD + * over the serial port (works in Windows and Linux, MAC?) + * The code reads a potentiometer plugged to an analog + * input and sends the data as a byte back to the computer. + * + * On the other side there will be a PureData sketch running + * comport2000 and will use the data to change a sound file + * properties. + * + * In order to make the data transfer as simple as possible + * we will only send a byte back to the computer, what means + * that the data coming from the ADC will be divided by 4. + * + * (cleft) 2005 DojoDave for K3 + * + * @author: David Cuartielles + * @context: ID3 - K3 - MAH - Sweden + */ + +int ledPin = 13; +int potPin = 0; +int ledStatus = LOW; + +void setup() { + pinMode(ledPin, OUTPUT); + Serial.begin(9600); +} + +void loop() { + Serial.print(analogRead(potPin)/4, BYTE); + delay(100); + ledStatus = !ledStatus; + digitalWrite(ledPin, ledStatus); +} diff --git a/build/shared/dist/examples/puredata/PD_two_potentiometers/PD_two_potentiometers.pde b/build/shared/dist/examples/puredata/PD_two_potentiometers/PD_two_potentiometers.pde new file mode 100644 index 000000000..8831413e9 --- /dev/null +++ b/build/shared/dist/examples/puredata/PD_two_potentiometers/PD_two_potentiometers.pde @@ -0,0 +1,31 @@ +/* Two Potentiometers + * ------------------ + * + * This program reads two potentiometers and + * sends the data to the computer. It combines + * both with PD or Processing + * + * (cleft) 2005 David Cuartielles for DojoCorp + * @author: D. Cuartielles + * @credit: Nima and Greg + * @date: 2005-11-18 + * @location: SFU, Vancouver, Canada + */ + +int potPin1 = 0; +int potPin2 = 1; + +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.print('A'); + Serial.print(analogRead(potPin1)); + Serial.println(); + delay(500); + Serial.print('B'); + Serial.print(analogRead(potPin2)); + Serial.println(); + delay(500); +} diff --git a/build/shared/dist/examples/pwm_sound/keyboard_serial/keyboard_serial.pde b/build/shared/dist/examples/pwm_sound/keyboard_serial/keyboard_serial.pde new file mode 100644 index 000000000..9aaa94fd1 --- /dev/null +++ b/build/shared/dist/examples/pwm_sound/keyboard_serial/keyboard_serial.pde @@ -0,0 +1,60 @@ +/* Keyboard Serial + * ---------------- + * + * Program to play tones depending on the + * data coming from the serial port. + * + * The calculation of the tones is made following the mathematical + * operation: + * + * timeHigh = 1/(2 * toneFrequency) = period / 2 + * + * where the different tones are described as in the table: + * + * note frequency period PW (timeHigh) + * c 261 Hz 3830 1915 + * d 294 Hz 3400 1700 + * e 329 Hz 3038 1519 + * f 349 Hz 2864 1432 + * g 392 Hz 2550 1275 + * a 440 Hz 2272 1136 + * b 493 Hz 2028 1014 + * C 523 Hz 1912 956 + * + * (cleft) 2005 D. Cuartielles for K3 + */ + +int ledPin = 13; +int speakerOut = 9; +byte names[] ={'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'}; +int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956}; +byte val = 0; +int serByte = -1; +int statePin = LOW; +int count = 0; + +void setup() { + pinMode(ledPin, OUTPUT); + pinMode(speakerOut, OUTPUT); + Serial.begin(9600); +} + +void loop() { + digitalWrite(speakerOut, LOW); + serByte = Serial.read(); + if (serByte != -1) { + val = serByte; + Serial.print(val); + statePin = !statePin; + digitalWrite(ledPin, statePin); + } + for (count=0;count<=8;count++) { + if (names[count] == val) { + digitalWrite(speakerOut, HIGH); + delayMicroseconds(tones[count]); + digitalWrite(speakerOut, LOW); + delayMicroseconds(tones[count]); + } + } +} + diff --git a/build/shared/dist/examples/pwm_sound/keyboard_serial_faded_volume/keyboard_serial_faded_volume.pde b/build/shared/dist/examples/pwm_sound/keyboard_serial_faded_volume/keyboard_serial_faded_volume.pde new file mode 100644 index 000000000..b160269e0 --- /dev/null +++ b/build/shared/dist/examples/pwm_sound/keyboard_serial_faded_volume/keyboard_serial_faded_volume.pde @@ -0,0 +1,62 @@ +/* Keyboard Serial + * ---------------- + * + * Program to play tones depending on the + * data coming from the serial port. + * + * The calculation of the tones is made following the mathematical + * operation: + * + * timeHigh = 1/(2 * toneFrequency) = period / 2 + * + * where the different tones are described as in the table: + * + * note frequency period PW (timeHigh) + * c 261 Hz 3830 1915 + * d 294 Hz 3400 1700 + * e 329 Hz 3038 1519 + * f 349 Hz 2864 1432 + * g 392 Hz 2550 1275 + * a 440 Hz 2272 1136 + * b 493 Hz 2028 1014 + * C 523 Hz 1912 956 + * + * We use the PWM on pin 9 and analogWrite to change volume + * + * (cleft) 2005 D. Cuartielles for K3 + */ + +int ledPin = 13; +int speakerOut = 9; +int volume = 300; // maximum volume is 1000 +byte names[] ={'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'}; +int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956}; +byte val = 0; +int serByte = -1; +int statePin = LOW; +int count = 0; + +void setup() { + pinMode(ledPin, OUTPUT); + Serial.begin(9600); +} + +void loop() { + analogWrite(speakerOut, 0); + serByte = Serial.read(); + if (serByte != -1) { + val = serByte; + Serial.print(val); + statePin = !statePin; + digitalWrite(ledPin, statePin); + } + for (count=0;count<=8;count++) { + if (names[count] == val) { + analogWrite(speakerOut,volume); + delayMicroseconds(tones[count]); + analogWrite(speakerOut, 0); + delayMicroseconds(tones[count]); + } + } +} + diff --git a/build/shared/dist/examples/pwm_sound/play_melody/play_melody.pde b/build/shared/dist/examples/pwm_sound/play_melody/play_melody.pde new file mode 100644 index 000000000..9b947e34a --- /dev/null +++ b/build/shared/dist/examples/pwm_sound/play_melody/play_melody.pde @@ -0,0 +1,67 @@ +/* Play Melody + * ----------- + * + * Program to play melodies stored in an array, it requires to know + * about timing issues and about how to play tones. + * + * The calculation of the tones is made following the mathematical + * operation: + * + * timeHigh = 1/(2 * toneFrequency) = period / 2 + * + * where the different tones are described as in the table: + * + * note frequency period PW (timeHigh) + * c 261 Hz 3830 1915 + * d 294 Hz 3400 1700 + * e 329 Hz 3038 1519 + * f 349 Hz 2864 1432 + * g 392 Hz 2550 1275 + * a 440 Hz 2272 1136 + * b 493 Hz 2028 1014 + * C 523 Hz 1912 956 + * + * (cleft) 2005 D. Cuartielles for K3 + */ + +int ledPin = 13; +int speakerOut = 9; +byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'}; +int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956}; +byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p"; +// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 +// 10 20 30 +int count = 0; +int count2 = 0; +int count3 = 0; +int MAX_COUNT = 24; +int statePin = LOW; + +void setup() { + pinMode(ledPin, OUTPUT); + pinMode(speakerOut, OUTPUT); +} + +void loop() { + digitalWrite(speakerOut, LOW); + for (count = 0; count < MAX_COUNT; count++) { + statePin = !statePin; + digitalWrite(ledPin, statePin); + for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) { + for (count2=0;count2<8;count2++) { + if (names[count2] == melody[count*2 + 1]) { + digitalWrite(speakerOut,HIGH); + delayMicroseconds(tones[count2]); + digitalWrite(speakerOut, LOW); + delayMicroseconds(tones[count2]); + } + if (melody[count*2 + 1] == 'p') { + // make a pause of a certain size + digitalWrite(speakerOut, 0); + delayMicroseconds(500); + } + } + } + } +} + diff --git a/build/shared/dist/examples/pwm_sound/play_melody_2/play_melody_2.pde b/build/shared/dist/examples/pwm_sound/play_melody_2/play_melody_2.pde new file mode 100644 index 000000000..9b947e34a --- /dev/null +++ b/build/shared/dist/examples/pwm_sound/play_melody_2/play_melody_2.pde @@ -0,0 +1,67 @@ +/* Play Melody + * ----------- + * + * Program to play melodies stored in an array, it requires to know + * about timing issues and about how to play tones. + * + * The calculation of the tones is made following the mathematical + * operation: + * + * timeHigh = 1/(2 * toneFrequency) = period / 2 + * + * where the different tones are described as in the table: + * + * note frequency period PW (timeHigh) + * c 261 Hz 3830 1915 + * d 294 Hz 3400 1700 + * e 329 Hz 3038 1519 + * f 349 Hz 2864 1432 + * g 392 Hz 2550 1275 + * a 440 Hz 2272 1136 + * b 493 Hz 2028 1014 + * C 523 Hz 1912 956 + * + * (cleft) 2005 D. Cuartielles for K3 + */ + +int ledPin = 13; +int speakerOut = 9; +byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'}; +int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956}; +byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p"; +// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 +// 10 20 30 +int count = 0; +int count2 = 0; +int count3 = 0; +int MAX_COUNT = 24; +int statePin = LOW; + +void setup() { + pinMode(ledPin, OUTPUT); + pinMode(speakerOut, OUTPUT); +} + +void loop() { + digitalWrite(speakerOut, LOW); + for (count = 0; count < MAX_COUNT; count++) { + statePin = !statePin; + digitalWrite(ledPin, statePin); + for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) { + for (count2=0;count2<8;count2++) { + if (names[count2] == melody[count*2 + 1]) { + digitalWrite(speakerOut,HIGH); + delayMicroseconds(tones[count2]); + digitalWrite(speakerOut, LOW); + delayMicroseconds(tones[count2]); + } + if (melody[count*2 + 1] == 'p') { + // make a pause of a certain size + digitalWrite(speakerOut, 0); + delayMicroseconds(500); + } + } + } + } +} + diff --git a/build/shared/dist/examples/pwm_sound/play_melody_faded_volume/play_melody_faded_volume.pde b/build/shared/dist/examples/pwm_sound/play_melody_faded_volume/play_melody_faded_volume.pde new file mode 100644 index 000000000..f1c55f640 --- /dev/null +++ b/build/shared/dist/examples/pwm_sound/play_melody_faded_volume/play_melody_faded_volume.pde @@ -0,0 +1,69 @@ +/* Play Melody - FD + * ---------------- + * + * Program to play melodies stored in an array, it requires to know + * about timing issues and about how to play tones. + * + * The calculation of the tones is made following the mathematical + * operation: + * + * timeHigh = 1/(2 * toneFrequency) = period / 2 + * + * where the different tones are described as in the table: + * + * note frequency period PW (timeHigh) + * c 261 Hz 3830 1915 + * d 294 Hz 3400 1700 + * e 329 Hz 3038 1519 + * f 349 Hz 2864 1432 + * g 392 Hz 2550 1275 + * a 440 Hz 2272 1136 + * b 493 Hz 2028 1014 + * C 523 Hz 1912 956 + * + * We use the PWM on pin 9 with analogWrite to change volume + * + * (cleft) 2005 D. Cuartielles for K3 + */ + +int ledPin = 13; +int speakerOut = 9; +int volume = 300; // maximum volume is 1000 +byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'}; +int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956}; +byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p"; +// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 +// 10 20 30 +int count = 0; +int count2 = 0; +int count3 = 0; +int MAX_COUNT = 24; +int statePin = LOW; + +void setup() { + pinMode(ledPin, OUTPUT); +} + +void loop() { + analogWrite(speakerOut, 0); + for (count = 0; count < MAX_COUNT; count++) { + statePin = !statePin; + digitalWrite(ledPin, statePin); + for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) { + for (count2=0;count2<8;count2++) { + if (names[count2] == melody[count*2 + 1]) { + analogWrite(speakerOut,volume); + delayMicroseconds(tones[count2]); + analogWrite(speakerOut, 0); + delayMicroseconds(tones[count2]); + } + if (melody[count*2 + 1] == 'p') { + // make a pause of a certain size + analogWrite(speakerOut, 0); + delayMicroseconds(500); + } + } + } + } +} + diff --git a/build/shared/dist/examples/sensors_complex/accelerometer_memsic2125/accelerometer_memsic2125.pde b/build/shared/dist/examples/sensors_complex/accelerometer_memsic2125/accelerometer_memsic2125.pde new file mode 100644 index 000000000..d1d7efa50 --- /dev/null +++ b/build/shared/dist/examples/sensors_complex/accelerometer_memsic2125/accelerometer_memsic2125.pde @@ -0,0 +1,91 @@ +/* Accelerometer Sensor + * -------------------- + * + * Reads an 2-D accelerometer + * attached to a couple of digital inputs and + * sends their values over the serial port; makes + * the monitor LED blink once sent + * + * + * http://www.0j0.org + * copyleft 2005 K3 - Malmo University - Sweden + * @author: Marcos Yarza + * @hardware: Marcos Yarza + * @project: SMEE - Experiential Vehicles + * @sponsor: Experiments in Art and Technology Sweden, 1:1 Scale + */ + +int ledPin = 13; +int xaccPin = 7; +int yaccPin = 6; +int value = 0; +int accel = 0; +char sign = ' '; + +int timer = 0; +int count = 0; + +void setup() { + Serial.begin(9600); // Sets the baud rate to 9600 + pinMode(ledPin, OUTPUT); + pinMode(xaccPin, INPUT); + pinMode(yaccPin, INPUT); +} + +/* (int) Operate Acceleration +* function to calculate acceleration +* returns an integer +*/ +int operateAcceleration(int time1) { + return abs(8 * (time1 / 10 - 500)); +} + +/* (void) readAccelerometer +* procedure to read the sensor, calculate +* acceleration and represent the value +*/ +void readAcceleration(int axe){ + timer = 0; + count = 0; + value = digitalRead(axe); + while(value == HIGH) { // Loop until pin reads a low + value = digitalRead(axe); + } + while(value == LOW) { // Loop until pin reads a high + value = digitalRead(axe); + } + while(value == HIGH) { // Loop until pin reads a low and count + value = digitalRead(axe); + count = count + 1; + } + timer = count * 18; //calculate the teme in miliseconds + + //operate sign + if (timer > 5000){ + sign = '+'; + } + if (timer < 5000){ + sign = '-'; + } + + //determine the value + accel = operateAcceleration(timer); + + //Represent acceleration over serial port + if (axe == xaccPin){ + Serial.print('X'); + } else { + Serial.print('Y'); + } + Serial.print(sign); + Serial.print(accel); + Serial.println(); +} + +void loop() { + readAcceleration(xaccPin); //reads and represents acceleration X + readAcceleration(yaccPin); //reads and represents acceleration Y + digitalWrite(ledPin, HIGH); + delay(300); + digitalWrite(ledPin, LOW); +} diff --git a/build/shared/dist/examples/sensors_complex/ultrasound_PING/ultrasound_PING.pde b/build/shared/dist/examples/sensors_complex/ultrasound_PING/ultrasound_PING.pde new file mode 100644 index 000000000..225010d2a --- /dev/null +++ b/build/shared/dist/examples/sensors_complex/ultrasound_PING/ultrasound_PING.pde @@ -0,0 +1,73 @@ +/* Ultrasound Sensor + * ----------------- + * + * Reads values (00014-01199) from an ultrasound sensor (3m sensor) + * and writes the values to the serialport. The sensor is the + * so-called PING sensor from Parallax/Devantech. + * + * http://www.xlab.se | http://www.0j0.org + * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp + * + */ + +int ultraSoundSignal = 8; // Ultrasound signal pin +int val = 0; +int ultrasoundValue = 0; +int timecount = 0; // Echo counter +int ledPin = 13; // LED connected to digital pin 13 + +void setup() { + Serial.begin(9600); // Sets the baud rate to 9600 + pinMode(ledPin, OUTPUT); // Sets the digital pin as output +} + +void loop() { +timecount = 0; +val = 0; +pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output + +/* Send low-high-low pulse to activate the trigger pulse of the sensor + * ------------------------------------------------------------------- + */ +digitalWrite(ultraSoundSignal, LOW); // Send low pulse +delayMicroseconds(2); // Wait for 2 microseconds +digitalWrite(ultraSoundSignal, HIGH); // Send high pulse +delayMicroseconds(5); // Wait for 5 microseconds +digitalWrite(ultraSoundSignal, LOW); // Holdoff + +/* Listening for echo pulse + * ------------------------------------------------------------------- + */ +pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input +val = digitalRead(ultraSoundSignal); // Append signal value to val + +while(val == LOW) { // Loop until pin reads a high value + val = digitalRead(ultraSoundSignal); +} + +while(val == HIGH) { // Loop until pin reads a high value + val = digitalRead(ultraSoundSignal); + timecount = timecount +1; // Count echo pulse time +} + +/* Writing out values to the serial port + * ------------------------------------------------------------------- + */ +ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue +Serial.print('A'); // Example identifier for the sensor +Serial.print(ultrasoundValue); +Serial.println(); + +/* Lite up LED if any value is passed by the echo pulse + * ------------------------------------------------------------------- + */ +if(timecount > 0){ + digitalWrite(ledPin, HIGH); +} + +/* Delay of program + * ------------------------------------------------------------------- + */ +delay(100); + +} diff --git a/build/shared/dist/examples/sensors_resistive/analog_read_led/analog_read_led.pde b/build/shared/dist/examples/sensors_resistive/analog_read_led/analog_read_led.pde new file mode 100644 index 000000000..d941e8487 --- /dev/null +++ b/build/shared/dist/examples/sensors_resistive/analog_read_led/analog_read_led.pde @@ -0,0 +1,29 @@ +/* Analog Read to LED + * ------------------ + * + * turns on and off a light emitting diode(LED) connected to digital + * pin 13. The amount of time the LED will be on and off depends on + * the value obtained by analogRead(). In the easiest case we connect + * a potentiometer to analog pin 2. + * + * Created 1 December 2005 + * copyleft 2005 DojoDave + * http://arduino.berlios.de + * + */ + +int potPin = 2; // select the input pin for the potentiometer +int ledPin = 13; // select the pin for the LED +int val = 0; // variable to store the value coming from the sensor + +void setup() { + pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT +} + +void loop() { + val = analogRead(potPin); // read the value from the sensor + digitalWrite(ledPin, HIGH); // turn the ledPin on + delay(val); // stop the program for some time + digitalWrite(ledPin, LOW); // turn the ledPin off + delay(val); // stop the program for some time +} diff --git a/build/shared/dist/examples/sensors_resistive/knock_sensor/knock_sensor.pde b/build/shared/dist/examples/sensors_resistive/knock_sensor/knock_sensor.pde new file mode 100644 index 000000000..14cbdb341 --- /dev/null +++ b/build/shared/dist/examples/sensors_resistive/knock_sensor/knock_sensor.pde @@ -0,0 +1,37 @@ +/* Knock Sensor + * ------------ + * + * Program using a Piezo element as if it was a knock sensor. + * + * We have to basically listen to an analog pin and detect + * if the signal goes over a certain threshold. It writes + * "knock" to the serial port if the Threshold is crossed, + * and toggles the LED on pin 13. + * + * Created 10 August 2005 + * copyleft 2005 DojoDave + * http://arduino.berlios.de + * + */ + +int ledPin = 13; // led connected to control pin 13 +int knockSensor = 0; // the knock sensor will be plugged at analog pin 0 +byte val = 0; // variable to store the value read from the sensor pin +int statePin = LOW; // variable used to store the last LED status, to toggle the light +int THRESHOLD = 100; // threshold value to decide when the detected sound is a knock or not + +void setup() { + pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT + Serial.begin(9600); // use the serial port +} + +void loop() { + val = analogRead(knockSensor); // read the sensor and store it in the variable "val" + if (val >= THRESHOLD) { + statePin = !statePin; // toggle the status of the ledPin (this trick doesn't use time cycles) + digitalWrite(ledPin, statePin); // turn the led on or off + Serial.println("Knock!"); // send the string "Knock!" back to the computer, followed by newline + } + delay(100); // we have to make a delay to avoid overloading the serial port +} + diff --git a/build/shared/dist/examples/sensors_resistive/read_joystick/read_joystick.pde b/build/shared/dist/examples/sensors_resistive/read_joystick/read_joystick.pde new file mode 100644 index 000000000..8763c8212 --- /dev/null +++ b/build/shared/dist/examples/sensors_resistive/read_joystick/read_joystick.pde @@ -0,0 +1,54 @@ +/* Read Jostick + * ------------ + * + * Reads two analog pins that are supposed to be + * connected to a jostick made of two potentiometers + * + * We send three bytes back to the computer: one header and + * two with data as signed bytes, this will take the form: + * + * Jxy\r\n + * + * x and y are integers and sent in ASCII + * + * created 20 June 2005 + * copyleft 2005 DojoDave for DojoCorp + * http://arduino.berlios.de + * + */ + +int ledPin = 13; // declare pin 13 for the LED +int joyPin1 = 0; // slider variable connecetd to analog pin 0 +int joyPin2 = 1; // slider variable connecetd to analog pin 1 +int value1 = 0; // variable to read the value from the analog pin 0 +int value2 = 0; // variable to read the value from the analog pin 1 + +void setup() +{ + pinMode(ledPin, OUTPUT); // initializes digital pins 0 to 7 as outputs + Serial.begin(9600); // turn on the serial port +} + +// function that transformes the data from a scale 0-1024 to a scale 0-9 +// and answers back the ASCII value for it +int treatValue(int data) +{ + return (data * 9 / 1024) + 48; +} + +void loop() +{ + value1 = analogRead(joyPin1); // reads the value of the variable resistor + delay(100); // this small pause is needed between reading two + // analog pins, otherwise we get the same value twice + value2 = analogRead(joyPin2); // reads the value of the variable resistor + + digitalWrite(ledPin, HIGH); // turn LED on + delay(value1/4); // wait depending on the value read for one axis + digitalWrite(ledPin, LOW); // turn LED off + delay(value2/4); // wait depending on the value read for the other axis + Serial.print('J'); // write a capital 'J' to the serial port + Serial.print(treatValue(value1), BYTE); // send the treated value for sensor 1 + Serial.print(treatValue(value2), BYTE); // send the treated value for sensor 2 + Serial.println(); +} diff --git a/build/shared/dist/examples/serial_comm/analog_read_send/analog_read_send.pde b/build/shared/dist/examples/serial_comm/analog_read_send/analog_read_send.pde new file mode 100644 index 000000000..850bd78c9 --- /dev/null +++ b/build/shared/dist/examples/serial_comm/analog_read_send/analog_read_send.pde @@ -0,0 +1,32 @@ +/* Analog Read Send + * ---------------- + * + * turns on and off a light emitting diode(LED) connected to digital + * pin 13. The amount of time the LED will be on and off depends on + * the value obtained by analogRead(). In the easiest case we connect + * a potentiometer to analog pin 2. Sends the data back to a computer + * over the serial port. + * + * Created 1 December 2005 + * copyleft 2005 DojoDave + * http://arduino.berlios.de + * + */ + +int potPin = 2; // select the input pin for the potentiometer +int ledPin = 13; // select the pin for the LED +int val = 0; // variable to store the value coming from the sensor + +void setup() { + pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT + Serial.begin(9600); // use the serial port to send the values back to the computer +} + +void loop() { + val = analogRead(potPin); // read the value from the sensor + Serial.println(val); // print the value to the serial port + digitalWrite(ledPin, HIGH); // turn the ledPin on + delay(val); // stop the program for some time + digitalWrite(ledPin, LOW); // turn the ledPin off + delay(val); // stop the program for some time +} diff --git a/build/shared/dist/examples/serial_comm/double_counter/double_counter.pde b/build/shared/dist/examples/serial_comm/double_counter/double_counter.pde new file mode 100644 index 000000000..22494055b --- /dev/null +++ b/build/shared/dist/examples/serial_comm/double_counter/double_counter.pde @@ -0,0 +1,37 @@ +/* Double Counter + * -------------- + * + * This program creates a double counter + * and sends the information over the port + * back to the computer. + * It can be used to test the connection of two different + * sensors to the board at the same time. + * + * (cleft) 2005 David Cuartielles for DojoCorp + * @author: D. Cuartielles + * @credits: Greg and Nima from SFU + */ + +int count = 0; + +void setup() { + Serial.begin(9600); +} + +void loop() { + // counter A will go forwards + Serial.print('A'); + Serial.print(count); + Serial.println(); + delay(1000); + + // counter B will go backwards + Serial.print('B'); + Serial.print(1024 - count); + Serial.println(); + delay(1000); + + // increase and reset the counter (if needed) + count++; + if (count == 1024) count = 0; +} diff --git a/build/shared/dist/examples/serial_comm/serialCom_strings/serialCom_strings.pde b/build/shared/dist/examples/serial_comm/serialCom_strings/serialCom_strings.pde new file mode 100644 index 000000000..ef2c9d41b --- /dev/null +++ b/build/shared/dist/examples/serial_comm/serialCom_strings/serialCom_strings.pde @@ -0,0 +1,86 @@ +/* ------------------------------------------------ +* SERIAL COM - HANDELING MULTIPLE BYTES inside ARDUINO - 04_function development +* by beltran berrocal +* +* this prog establishes a connection with the pc and waits for it to send him +* a long string of characters like "hello Arduino!". +* Then Arduino informs the pc that it heard the whole sentence +* +* the same as examlpe 03 but it deploys 2 reusable functions. +* for doing the same job. +* readSerialString() and printSerialString() +* you just need to instantiate an array that will hold all the chars of the string +* I've put a 100 value for excess, but if you exactly know how many bytes you are expecting +* simply write it down inside the brackets [yourLengthHere] +* +* created 16 Decembre 2005; +* copyleft 2005 Progetto25zero1 +* +* --------------------------------------------------- */ + +char serInString[100]; // array that will hold the different bytes of the string. 100=100characters; + // -> you must state how long the array will be else it won't work properly + +//read a string from the serial and store it in an array +//you must supply the array variable +void readSerialString (char *strArray) { + int i = 0; + if(Serial.available()) { + Serial.print("reading Serial String: "); //optional: for confirmation + while (serialAvailable()){ + strArray[i] = Serial.read(); + i++; + Serial.write(strArray[(i-1)]); //optional: for confirmation + } + Serial.println(); //optional: for confirmation + } +} + +//Print the whole string at once - will be performed only if thers is data inside it +//you must supply the array variable +void printSerialString(char *strArray) { + int i=0; + if (strArray[i] != 0) { + while(strArray[i] != 0) { + Serial.print( strArray[i] ); + strArray[i] = 0; // optional: flush the content + i++; + } + } +} + +//utility function to know wither an array is empty or not +boolean isStringEmpty(char *strArray) { + if (strArray[0] == 0) { + return true; + } else { + return false; + } +} + +void setup() { + Serial.begin(9600); +} + +void loop () { + //simple feedback from Arduino + Serial.println("Hello World"); + + //read the serial port and create a string out of what you read + readSerialString(serInString); + + //do somenthing else perhaps wait for other data or read another Serial string + Serial.println("------------ arduino is doing somenthing else "); + + + if( isStringEmpty(serInString) == false) { //this check is optional + Serial.println("Arduino recorded that you said: "); + //try to print out collected information. it will do it only if there actually is some info. + printSerialString(serInString); + Serial.println(); + } + + Serial.println(); + //slows down the visualization in the terminal + delay(2000); +} diff --git a/build/shared/dist/examples/serial_comm/serial_read_advanced/serial_read_advanced.pde b/build/shared/dist/examples/serial_comm/serial_read_advanced/serial_read_advanced.pde new file mode 100644 index 000000000..34c8fc114 --- /dev/null +++ b/build/shared/dist/examples/serial_comm/serial_read_advanced/serial_read_advanced.pde @@ -0,0 +1,43 @@ +/* Serial Read Advanced + * -------------------- + * + * turns on and off a light emitting diode(LED) connected to digital + * pin 13. The LED will light up when receiving a 'H' over the serial + * port. The LED will blink shortly. + * + * Created 1 December 2005 + * copyleft 2005 DojoDave + * http://arduino.berlios.de + * + */ + +int ledPin = 13; // select the pin for the LED +int val = 0; // variable to store the data from the serial port +int serbyte = 0; // variable to store the VALID data from the port + +void setup() { + pinMode(ledPin,OUTPUT); // declare the LED's pin as output + Serial.begin(9600); // connect to the serial port +} + +void loop () { + // read the serial port + serbyte = Serial.read(); + + // if the input is '-1' then there is no data + // at the input, otherwise store it + if (val != -1) { + val = serbyte; + } + + // if the stored value is 'H' turn the LED on + if (val == 'H') { + digitalWrite(ledPin, HIGH); + } else { + digitalWrite(ledPin, LOW); + } + + delay(200); + +} + diff --git a/build/shared/dist/examples/serial_comm/serial_read_basic/serial_read_basic.pde b/build/shared/dist/examples/serial_comm/serial_read_basic/serial_read_basic.pde new file mode 100644 index 000000000..cffd7da02 --- /dev/null +++ b/build/shared/dist/examples/serial_comm/serial_read_basic/serial_read_basic.pde @@ -0,0 +1,35 @@ +/* Serial Read Basic + * ----------------- + * + * turns on and off a light emitting diode(LED) connected to digital + * pin 13. The LED will light up when receiving a 'H' over the serial + * port. The LED will blink shortly. + * + * Created 1 December 2005 + * copyleft 2005 DojoDave + * http://arduino.berlios.de + * + */ + +int ledPin = 13; // select the pin for the LED +int val = 0; // variable to store the data from the serial port + +void setup() { + pinMode(ledPin,OUTPUT); // declare the LED's pin as output + Serial.begin(9600); // connect to the serial port +} + +void loop () { + // read the serial port + val = Serial.read(); + + // if the input is '-1' then there is no data + // at the input, otherwise check out if it is 'H' + if (val != -1) { + if (val == 'H') { + digitalWrite(ledPin, HIGH); + delay(200); + digitalWrite(ledPin, LOW); + } + } +} diff --git a/build/shared/dist/examples/serial_comm/serial_write_basic/serial_write_basic.pde b/build/shared/dist/examples/serial_comm/serial_write_basic/serial_write_basic.pde new file mode 100644 index 000000000..fa4f2be48 --- /dev/null +++ b/build/shared/dist/examples/serial_comm/serial_write_basic/serial_write_basic.pde @@ -0,0 +1,40 @@ +/* Serial Write Basic + * ------------------ + * + * turns on and off a light emitting diode(LED) connected to digital + * pin 13. The LED will light up when pressing a button. At the same + * time, Arduino will send two different strings over the serial + * port depending if the button is pressed or released. + * + * Created 1 December 2005 + * copyleft 2005 DojoDave + * http://arduino.berlios.de + * + */ + +int ledPin = 13; // select the pin for the LED +int buttonPin = 2; // select the pin for the button +int val = 0; // variable to store the data from the serial port + +void setup() { + pinMode(ledPin,OUTPUT); // declare the LED's pin as output + pinMode(buttonPin, INPUT); // delcare the button pin as input + Serial.begin(9600); // connect to the serial port +} + +void loop () { + // read the button and store the value + val = digitalRead(buttonPin); + + // if the button is at HIGH, turn the LED on, off otherwise + if (val == HIGH) { + Serial.print("HIGH"); + digitalWrite(ledPin, HIGH); + } else { + Serial.print("LOW"); + digitalWrite(ledPin, LOW); + } + + Serial.println(); + delay(1000); // convenient to use delays when sending stuff back to the comp. +} diff --git a/build/windows/make.sh b/build/windows/make.sh index 1091d961d..82ab2a9d1 100755 --- a/build/windows/make.sh +++ b/build/windows/make.sh @@ -73,14 +73,15 @@ else #cp dist/core/makefile.win work/core/Makefile cp -r ../../targets work/lib/ - # take care of the examples - mkdir work/examples - cd work/examples - cp ../../../shared/dist/examples.zip . - echo Extracting examples ... - unzip -q -d . examples.zip - rm -f examples.zip - cd ../.. + # take care of the examples + cp -r ../shared/dist/examples work/ + #mkdir work/examples + #cd work/examples + #cp ../../../shared/dist/examples.zip . + #echo Extracting examples ... + #unzip -q -d . examples.zip + #rm -f examples.zip + #cd ../.. # chmod +x the crew find work -name "*.dll" -exec chmod +x {} ';' diff --git a/readme.txt b/readme.txt index 6bd07b97d..5963d9a99 100644 --- a/readme.txt +++ b/readme.txt @@ -58,6 +58,7 @@ Now display binary sketch size on upload, and give error if too big. Added C++ serial library. Resynced with Processing/Wiring IDE code (improved auto-format, faster logging to serial monitor console, other bug fixes) +New library system. 0003 - 2006.01.16