diff --git a/examples/osd/lgb-train/BBL298Demo/BBL298Demo.ino b/examples/osd/lgb-train/BBL298Demo/BBL298Demo.ino new file mode 100644 index 000000000..d0a0d8f8e --- /dev/null +++ b/examples/osd/lgb-train/BBL298Demo/BBL298Demo.ino @@ -0,0 +1,111 @@ +/**********************************************************************************/ +/* Demo Program for: */ +/* Board: BB-L298 */ +/* Manufacture: OLIMEX */ +/* COPYRIGHT (C) 2013 */ +/* Designed by: Engineer Penko T. Bozhkov */ +/* Module Name : main module */ +/* File Name : main.c */ +/* Revision : 1.0.0 (initial) */ +/* Date : 11.09.2013 */ +/* Built with Arduino C/C++ Compiler, version: 1.0.5 */ +/**********************************************************************************/ + +// Description: This simple program is designed by using Olimexino-328 board and BB-L298 connected to it. +// |---------------------------------------------------------------------------| +// | The connections were as follows: | +// |--------------------------------|------------------------------------------| +// |Connector at Olimexino-328 | Connector at BB-L298 | +// |--------------------------------|------------------------------------------| +// | Power<3>, 5V | CTRL<1>, +5V | +// | Power<4>, GND | CTRL<8>, GND | +// | Power<5>, GND | PWR<2>, GND | +// | Power<6>, VIN(@12VDC) | PWR<1>, VIN | +// | DIGITAL<3>, D3 | CTRL<2>, Enable_A | +// | DIGITAL<4>, D4 | CTRL<3>, IN1 | +// | DIGITAL<5>, D5 | CTRL<4>, IN2 | +// | DIGITAL<6>, D6 | CTRL<5>, Enable_B | +// | DIGITAL<7>, D7 | CTRL<6>, IN3 | +// | DIGITAL<8>, D8 | CTRL<7>, IN4 | +// |--------------------------------|------------------------------------------| +// A 12VDC 2-phase step engine(rotates 18 degree per step) was connected to the BB-L298 board's connectors MT1 ans MT2. +// When the program is running, the motor makes one 360 degree clockwise rotation(if connected correctly). +// Then one 360 degree counterclockwise rotation. Afterwards the described cycle is constantly repeated. +// The step engine must be connected as follows: Coil<1>*(Begin) to OUT1; Coil<1>(End) to OUT2 +// Coil<2>*(Begin) to OUT3; Coil<2>(End) to OUT4 + + +// set pin numbers: +const int LED = 13; +const int Enable_A = 3; // A low-to-high transition on the STEP input sequences the translator and advances the motor one increment. +const int IN1 = 4; // Direction of rotation +const int IN2 = 5; // Mode of operation: Active/Sleep +const int Enable_B = 6; // Enable/Disable the Driver operation +const int IN3 = 7; // Reset when active turns off all of the FET outputs +const int IN4 = 8; // Microstep Select +const int Threshold = 20; + +#define IN1_L digitalWrite(IN1, LOW); +#define IN1_H digitalWrite(IN1, HIGH); +#define IN2_L digitalWrite(IN2, LOW); +#define IN2_H digitalWrite(IN2, HIGH); +#define IN3_L digitalWrite(IN3, LOW); +#define IN3_H digitalWrite(IN3, HIGH); +#define IN4_L digitalWrite(IN4, LOW); +#define IN4_H digitalWrite(IN4, HIGH); + +// Variables will change: +long previousMillis = 0; // will store last time STEP was updated +int counter = 0; +volatile int index = 1; +int DIR = 0; +long interval = 100; // interval at which to make a STEP + +void setup() { + // set the digital pin as output: + pinMode(LED, OUTPUT); + pinMode(Enable_A, OUTPUT); + pinMode(Enable_B, OUTPUT); + pinMode(IN1, OUTPUT); + pinMode(IN2, OUTPUT); + pinMode(IN3, OUTPUT); + pinMode(IN4, OUTPUT); + + //Set the state + digitalWrite(LED, LOW); + digitalWrite(Enable_A, HIGH); + digitalWrite(Enable_B, HIGH); + digitalWrite(IN1, LOW); + digitalWrite(IN2, LOW); + digitalWrite(IN3, LOW); + digitalWrite(IN4, LOW); + +} + +void loop() +{ + unsigned long currentMillis = millis(); + + if(currentMillis - previousMillis > interval) { + previousMillis = currentMillis; + + counter++; + + if( index == 1){ IN1_H; IN2_L; IN3_L; IN4_L; } + else if(index == 2){ IN1_L; IN2_L; IN3_H; IN4_L; } + else if(index == 3){ IN1_L; IN2_H; IN3_L; IN4_L; } + else if(index == 4){ IN1_L; IN2_L; IN3_L; IN4_H; } + + if(counter >= Threshold){ + counter = 0; + if(DIR){ DIR = 0; } + else{ DIR = 1; } + if( digitalRead(LED) == HIGH ){ digitalWrite(LED, LOW); } + else{ digitalWrite(LED, HIGH); } + } + + if(DIR){ index++; if(index >4 ){ index = 1; } } + else{ index--; if(index <1 ){ index = 4; } } + + } +} \ No newline at end of file diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/.gitattributes b/examples/osd/lgb-train/Grove_LED_Bar-master/.gitattributes new file mode 100644 index 000000000..412eeda78 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/.gitattributes @@ -0,0 +1,22 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Custom for Visual Studio +*.cs diff=csharp +*.sln merge=union +*.csproj merge=union +*.vbproj merge=union +*.fsproj merge=union +*.dbproj merge=union + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/.gitignore b/examples/osd/lgb-train/Grove_LED_Bar-master/.gitignore new file mode 100644 index 000000000..b9d6bd92f --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/.gitignore @@ -0,0 +1,215 @@ +################# +## Eclipse +################# + +*.pydevproject +.project +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.classpath +.settings/ +.loadpath + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# CDT-specific +.cproject + +# PDT-specific +.buildpath + + +################# +## Visual Studio +################# + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates + +# Build results + +[Dd]ebug/ +[Rr]elease/ +x64/ +build/ +[Bb]in/ +[Oo]bj/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +*_i.c +*_p.c +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.log +*.scc + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +*.ncrunch* +.*crunch*.local.xml + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.Publish.xml +*.pubxml + +# NuGet Packages Directory +## TODO: If you have NuGet Package Restore enabled, uncomment the next line +#packages/ + +# Windows Azure Build Output +csx +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.[Pp]ublish.xml +*.pfx +*.publishsettings + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file to a newer +# Visual Studio version. Backup files are not needed, because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +App_Data/*.mdf +App_Data/*.ldf + +############# +## Windows detritus +############# + +# Windows image file caches +Thumbs.db +ehthumbs.db + +# Folder config file +Desktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Mac crap +.DS_Store + + +############# +## Python +############# + +*.py[co] + +# Packages +*.egg +*.egg-info +dist/ +build/ +eggs/ +parts/ +var/ +sdist/ +develop-eggs/ +.installed.cfg + +# Installer logs +pip-log.txt + +# Unit test / coverage reports +.coverage +.tox + +#Translations +*.mo + +#Mr Developer +.mr.developer.cfg diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/Grove_LED_Bar.cpp b/examples/osd/lgb-train/Grove_LED_Bar-master/Grove_LED_Bar.cpp new file mode 100644 index 000000000..c1c5ee285 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/Grove_LED_Bar.cpp @@ -0,0 +1,206 @@ +/* + LED bar library V2.0 + Copyright (c) 2010 Seeed Technology Inc. + + Original Author: LG + + Modify: Loovee, 2014-2-26 + User can choose which Io to be used. + + The MIT License (MIT) + + Copyright (c) 2013 Seeed Technology Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "Grove_LED_Bar.h" + +Grove_LED_Bar::Grove_LED_Bar(unsigned char pinClock, unsigned char pinData, bool greenToRed) +{ + __pinClock = pinClock; + __pinData = pinData; + __greenToRed = greenToRed; // ascending or decending + + for (byte i = 0; i < 10; i++) + __state[i] = 0x00; // persist state so individual leds can be toggled + + pinMode(__pinClock, OUTPUT); + pinMode(__pinData, OUTPUT); +} + + +// Send the latch command +void Grove_LED_Bar::latchData() +{ + digitalWrite(__pinData, LOW); + delayMicroseconds(10); + + for (unsigned char i = 0; i < 4; i++) + { + digitalWrite(__pinData, HIGH); + digitalWrite(__pinData, LOW); + } +} + + +// Send 16 bits of data +void Grove_LED_Bar::sendData(unsigned int data) +{ + unsigned int state = 0; + for (unsigned char i = 0; i < 16; i++) + { + unsigned int state1 = (data & 0x8000) ? HIGH : LOW; + digitalWrite(__pinData, state1); + + //state = digitalRead(__pinClock) ? LOW : HIGH; + state = 1-state; + digitalWrite(__pinClock, state); + + data <<= 1; + } +} + + +// Change the orientation +// Green to red, or red to green +void Grove_LED_Bar::setGreenToRed(bool greenToRed) +{ + __greenToRed = greenToRed; + + setData(__state); +} + + +// Set level (0-10) +// Level 0 means all leds off +// Level 10 means all leds on +// Level 4.5 means 4 LEDs on and the 5th LED's half on +void Grove_LED_Bar::setLevel(float level) +{ + level = max(0, min(10, level)); + level *= 8; // there are 8 (noticable) levels of brightness on each segment + + // Place number of 'level' of 1-bits on __state + for (byte i = 0; i < 10; i++) { + __state[i] = (level > 8) ? ~0 : + (level > 0) ? ~(~0 << byte(level)) : 0; + + level -= 8; + }; + + setData(__state); +} + + +// Set a single led +// led (1-10) +// brightness (0-1) +void Grove_LED_Bar::setLed(unsigned char led, float brightness) +{ + led = max(1, min(10, led)); + brightness = max(0, min(brightness, 1)); + + // Zero based index 0-9 for bitwise operations + led--; + + // 8 (noticable) levels of brightness + // 00000000 darkest + // 00000011 brighter + // ........ + // 11111111 brightest + __state[led] = ~(~0 << (unsigned char) (brightness*8)); + + setData(__state); +} + + +// Toggle a single led +// led (1-10) +void Grove_LED_Bar::toggleLed(unsigned char led) +{ + led = max(1, min(10, led)); + + // Zero based index 0-9 for bitwise operations + led--; + + __state[led] = __state[led] ? 0 : ~0; + + setData(__state); +} + +// each element in the state will hold the brightness level +// 00000000 darkest +// 00000011 brighter +// ........ +// 11111111 brightest +void Grove_LED_Bar::setData(unsigned char __state[]) +{ + + sendData(GLB_CMDMODE); + + for (unsigned char i = 0; i < 10; i++) + { + if (__greenToRed) + { + // Go backward on __state + sendData(__state[10-i-1]); + } + else + { + // Go forward on __state + sendData(__state[i]); + } + } + + // Two extra empty bits for padding the command to the correct length + sendData(0x00); + sendData(0x00); + + latchData(); +} + +void Grove_LED_Bar::setBits(unsigned int bits) +{ + + for (unsigned char i = 0; i < 10; i++) + { + + if ((bits % 2) == 1) + __state[i] = 0xFF; + else + __state[i] = 0x00; + bits /= 2; + } + + setData(__state); +} + + +// Return the current bits +unsigned int const Grove_LED_Bar::getBits() +{ + unsigned int __bits = 0x00; + for (unsigned char i = 0; i < 10; i++) + { + if (__state[i] != 0x0) + __bits |= (0x1 << i); + } + return __bits; +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/Grove_LED_Bar.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/Grove_LED_Bar.gif new file mode 100644 index 000000000..909ee6c8f Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/Grove_LED_Bar.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/Grove_LED_Bar.h b/examples/osd/lgb-train/Grove_LED_Bar-master/Grove_LED_Bar.h new file mode 100644 index 000000000..5deff5231 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/Grove_LED_Bar.h @@ -0,0 +1,73 @@ +/* + LED bar library V2.0 + Copyright (c) 2010 Seeed Technology Inc. + + Original Author: LG + + Modify: Loovee, 2014-2-26 + User can choose which Io to be used. + + Modify: Long, 2015-01-07 + User can change the brightness level for each LED segment + Rename constant to avoid name conflict + + The MIT License (MIT) + + Copyright (c) 2013 Seeed Technology Inc. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. + +*/ +#ifndef Grove_LED_Bar_H +#define Grove_LED_Bar_H + +#include + +// Avoid name conflict +#define GLB_CMDMODE 0x00 // Work on 8-bit mode +#define GLB_ON 0xff // 8-bit 1 data +#define GLB_OFF 0x00 // 8-bit 0 data + +class Grove_LED_Bar +{ + +private: + + unsigned int __pinClock; // Clock pin + unsigned int __pinData; // Data pin + bool __greenToRed; // Orientation (0 = red to green, 1 = green to red) + unsigned char __state[10];// Led state, brightness for each LED + + void sendData(unsigned int data); // Send a word to led bar + void latchData(void); // Load data into the latch register + void setData(unsigned char bits[]);//Set data array + +public: + + Grove_LED_Bar(unsigned char pinClock, unsigned char pinData, bool greenToRed); // Initialize + void begin(){pinMode(__pinClock, OUTPUT); pinMode(__pinData, OUTPUT);} + void setGreenToRed(bool greenToRed); // (Re)set orientation + void setLevel(float level); // Set level, range from 0 to 10 + void setLed(unsigned char led, float brightness);// Set brightness for a single led, range from 0 to 1 + void toggleLed(unsigned char led); // Toggle a single led + void setBits(unsigned int bits); // Toggle leds to match given bits + unsigned int const getBits(); // Get the current state +}; + +#endif diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/BasicControl/BasicControl.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/BasicControl/BasicControl.gif new file mode 100644 index 000000000..b0770d1d8 Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/BasicControl/BasicControl.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/BasicControl/BasicControl.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/BasicControl/BasicControl.ino new file mode 100644 index 000000000..933b2477e --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/BasicControl/BasicControl.ino @@ -0,0 +1,79 @@ +/* +Grove LED Bar - Basic Control Example +This example will show you how to use the setBits() function of this library. +Set any combination of LEDs using 10 bits. +Least significant bit controls the first LED. + +The setBits() function sets the current state, one bit for each LED. +First 10 bits from the right control the 10 LEDs. + +eg. 0b00000jihgfedcba +a = LED 1, b = LED 2, c = LED 3, etc. + +dec hex binary +0 = 0x0 = 0b000000000000000 = all LEDs off +5 = 0x05 = 0b000000000000101 = LEDs 1 and 3 on, all others off +341 = 0x155 = 0b000000101010101 = LEDs 1,3,5,7,9 on, 2,4,6,8,10 off +1023 = 0x3ff = 0b000001111111111 = all LEDs on + | | + 10 1 + +The bits >10 are ignored, shown here as x: 0bxxxxx0000000000 + +Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette +*/ + +#include + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar(7, 6, 0); + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar(35, 36, 0); + +void setup() +{ + // nothing to initialize + bar.begin(); + +} + +void loop() +{ + // Turn on all LEDs + bar.setBits(0x3ff); + delay(1000); + + // Turn off all LEDs + bar.setBits(0x0); + delay(1000); + + // Turn on LED 1 + // 0b000000000000001 can also be written as 0x1: + bar.setBits(0b000000000000001); + delay(1000); + + // Turn on LEDs 1 and 3 + // 0b000000000000101 can also be written as 0x5: + bar.setBits(0b000000000000101); + delay(1000); + + // Turn on LEDs 1, 3, 5, 7, 9 + bar.setBits(0x155); + delay(1000); + + // Turn on LEDs 2, 4, 6, 8, 10 + bar.setBits(0x2AA); + delay(1000); + + // Turn on LEDs 1, 2, 3, 4, 5 + // 0b000000000011111 == 0x1F + bar.setBits(0b000000000011111); + delay(1000); + + // Turn on LEDs 6, 7, 8, 9, 10 + // 0b000001111100000 == 0x3E0 + bar.setBits(0b000001111100000); + delay(1000); +} + diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Bounce/Bounce.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Bounce/Bounce.gif new file mode 100644 index 000000000..ff3bfe01d Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Bounce/Bounce.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Bounce/Bounce.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Bounce/Bounce.ino new file mode 100644 index 000000000..6957c61a8 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Bounce/Bounce.ino @@ -0,0 +1,52 @@ +/* +Grove LED Bar - Bounce Example +This example will show you how to use getBits() function of this library. +The getBits() function returns the current state so you can modify it. +Use the setBits() function to save the new state. + +Ported to MSP-EXP430F5529, and TM4C123 (Tiva C) by Cameron P. LaFollette + +*/ + +#include + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar(7, 6, 0); + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation + +unsigned int state; + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Switch on the first two LEDs + bar.setLevel(2); + + // Get the current state (which is 0x3) + state = bar.getBits(); + + // Bounce to the right + for (int i = 0; i < 8; i++) + { + // Bit shift left and update + state <<= 1; + bar.setBits(state); + delay(200); + } + + // Bounce to the left + for (int i = 0; i < 8; i++) + { + // Bit shift right and update + state >>= 1; + bar.setBits(state); + delay(200); + } +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/ControlSingleLed/ControlSingleLed.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/ControlSingleLed/ControlSingleLed.gif new file mode 100644 index 000000000..01c8e96ba Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/ControlSingleLed/ControlSingleLed.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/ControlSingleLed/ControlSingleLed.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/ControlSingleLed/ControlSingleLed.ino new file mode 100644 index 000000000..16c8aeb83 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/ControlSingleLed/ControlSingleLed.ino @@ -0,0 +1,67 @@ +/* +Grove LED Bar - Control Single LED Example +This example will show you how to use the setLed() function of this library. +There are 10 LEDs in the Grove LED Bar. +Use this method to set a single LED. + +Syntax setLed(led, state) +led (1-10) +state (0=off, 1=on) + +Ported for TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette +*/ + +#include +//Arduino +//Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +// LaunchPad +Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation + + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Set LED 3 on + bar.setLed(3, 1); + delay(500); + + // Set LED 5 on + bar.setLed(5, 1); + delay(500); + + // Set LED 7 on + bar.setLed(7, 1); + delay(500); + + // Set LED 3 off + bar.setLed(3, 0); + delay(500); + + // Set LED 5 off + bar.setLed(5, 0); + delay(500); + + // Set LED 7 off + bar.setLed(7, 0); + delay(500); + + // Turn all LEDs on + for (int i = 1; i <= 10; i++) + { + bar.setLed(i, 1); + delay(500); + } + + // Turn all LEDs off + for (int i = 1; i <= 10; i++) + { + bar.setLed(i, 0); + delay(500); + } +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Level/Level.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Level/Level.gif new file mode 100644 index 000000000..f85eea136 Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Level/Level.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Level/Level.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Level/Level.ino new file mode 100644 index 000000000..379076d00 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Level/Level.ino @@ -0,0 +1,37 @@ +/* +Grove LED Bar - Level Example +This example will show you how to use setLevel() function of this library. +The setLevel() function illuminates the given number of LEDs from either side. + +Syntax setLevel(level) +0 = all LEDs off +5 = 5 LEDs on +10 = all LEDs on + +Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette +*/ + +#include + + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Walk through the levels + for (int i = 0; i <= 10; i++) + { + bar.setLevel(i); + delay(100); + } +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/README.md b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/README.md new file mode 100644 index 000000000..0ad2bdcd4 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/README.md @@ -0,0 +1,44 @@ +# Examples + +## BasicControl +![BasicControl](BasicControl/BasicControl.gif) + +---- + +## Bounce +![Bounce](Bounce/Bounce.gif) + +---- + +## ControlSingleLed +![ControlSingleLed](ControlSingleLed/ControlSingleLed.gif) + +---- + +## Level +![Level](Level/Level.gif) + +---- + +## Random +![Random](Random/Random.gif) + +---- + +## Reverse +![Reverse](Reverse/Reverse.gif) + +---- + +## Toggle +![Toggle](Toggle/Toggle.gif) + +---- + +## Walk +![Walk](Walk/Walk.gif) + +---- + +## WalkMultiple +Same as the Walk example, only with two Grove LED bars, the second initialised in reverse mode. diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Random/Random.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Random/Random.gif new file mode 100644 index 000000000..09b5fe72b Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Random/Random.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Random/Random.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Random/Random.ino new file mode 100644 index 000000000..1538d3f5e --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Random/Random.ino @@ -0,0 +1,28 @@ +/* +Grove LED Bar - Random Example +This example will show you how to use setBits() function of this library. +Set any combination of LEDs using 10 bits. + +Ported for MSP-EXP430F5529 TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette +*/ + +#include + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Display a random value between 0 (all LEDs off) and 1023 (all LEDs on) + bar.setBits(random(1024)); + delay(50); +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Reverse/Reverse.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Reverse/Reverse.gif new file mode 100644 index 000000000..37fc0db4c Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Reverse/Reverse.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Reverse/Reverse.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Reverse/Reverse.ino new file mode 100644 index 000000000..e8213f001 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Reverse/Reverse.ino @@ -0,0 +1,65 @@ +/* +Grove LED Bar - Reverse Example +This example will show you how to use setGreenToRed() function of this library. +The function is used to reverse the orientation of the LED Bar. +Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette +*/ + +#include + +// The 3rd parameter sets the initial orientation +// 0 = green to red, 1 = red to green +// You can always change it at runtime with the setGreenToRed() function + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Start as red to green + // Walk through the 10 levels + for (int i = 0; i <= 10; i++) + { + bar.setLevel(i); + delay(200); + } + bar.setLevel(0); + + // Swich to green to red + bar.setGreenToRed(1); + + // Walk through the 10 levels + for (int i = 0; i <= 10; i++) + { + bar.setLevel(i); + delay(200); + } + bar.setLevel(0); + + // Switch back to red to green + bar.setGreenToRed(0); + delay(200); + + // Walk through the levels + // Each reverse keeps the previously set level + for (int i = 1; i <= 10; i++) + { + bar.setLevel(i); + delay(500); + + bar.setGreenToRed(1); + delay(500); + + bar.setGreenToRed(0); + } + bar.setLevel(0); +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Toggle/Toggle.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Toggle/Toggle.gif new file mode 100644 index 000000000..33e47b338 Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Toggle/Toggle.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Toggle/Toggle.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Toggle/Toggle.ino new file mode 100644 index 000000000..102c9fa87 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Toggle/Toggle.ino @@ -0,0 +1,48 @@ +/* +Grove LED Bar - Toggle Example +This example will show you how to use toggleLed() function of this library. +The function lets you set a single led to the opposite of it's current value. + +Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette +*/ + +#include + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Start with all LEDs illuminated + bar.setLevel(10); + delay(1000); + + // Turn off LED 3 + bar.toggleLed(3); + delay(1000); + + // Turn on LED 3 + bar.toggleLed(3); + delay(1000); + + // Switch off all LEDs + bar.setLevel(0); + delay(1000); + + // Turn on LED 7 + bar.toggleLed(7); + delay(1000); + + // Turn off LED 7 + bar.toggleLed(7); + delay(1000); +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/V3_ControlSingleLed/V3_ControlSingleLed.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/V3_ControlSingleLed/V3_ControlSingleLed.ino new file mode 100644 index 000000000..3be74a096 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/V3_ControlSingleLed/V3_ControlSingleLed.ino @@ -0,0 +1,41 @@ +/* +Grove LED Bar - Control Single LED Example +... + +Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette +*/ + +#include + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation + + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Simulate police LED lights using setLed method + for (float i = 0; i < 1.1; i += .125f) { + bar.setLed(1, i); + bar.setLed(2, i); + bar.setLed(3, 1 - i); + bar.setLed(4, 1 - i); + delay(50); + }; + + for (float i = 0; i < 1.1; i += .125f) { + bar.setLed(1, 1 - i); + bar.setLed(2, 1 - i); + bar.setLed(3, i); + bar.setLed(4, i); + delay(50); + }; +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/V3_Level/V3_Level.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/V3_Level/V3_Level.ino new file mode 100644 index 000000000..fa00e55a0 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/V3_Level/V3_Level.ino @@ -0,0 +1,43 @@ +/* +Grove LED Bar - Brightness Level Example +... +Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette +*/ + +#include + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + bar.setGreenToRed(false); + for (float i = 0; i < 10.1; i += 0.125) { + bar.setLevel(i); + delay(25); + }; + for (float i = 0; i < 10.1; i += 0.125) { + bar.setLevel(10-i); + delay(25); + }; + + // Change orientation + bar.setGreenToRed(true); + for (float i = 0; i < 10.1; i += 0.125) { + bar.setLevel(i); + delay(25); + }; + for (float i = 0; i < 10.1; i += 0.125) { + bar.setLevel(10-i); + delay(25); + }; +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/V3_Wave/V3_Wave.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/V3_Wave/V3_Wave.ino new file mode 100644 index 000000000..6f06fbeae --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/V3_Wave/V3_Wave.ino @@ -0,0 +1,57 @@ +/* +Grove LED Bar - Wave Example +... +Ported for MSP-EXP430F5529, TM4C123 (Tiva C) by Cameron P. LaFollette +*/ + +#include + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +// Frames of continuous waves +unsigned char state[] = +{ + 0b11111111, + 0b01111111, + 0b00111111, + 0b00011111, + 0b00001111, + 0b00000111, + 0b00000011, + 0b00000001, + 0b00000000, + 0b00000001, + 0b00000011, + 0b00000111, + 0b00001111, + 0b00011111, + 0b00111111, + 0b01111111, + 0b11111111, + 0b01111111, + 0b00111111, + 0b00011111, + 0b00001111, + 0b00000111, + 0b00000011, + 0b00000001, + 0b00000000 +}; + +void loop() +{ + for (byte i = 0; i < (sizeof(state)-9); i++) { + bar.setBits((unsigned int)state[i]); + delay(50); + }; +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Walk/Walk.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Walk/Walk.gif new file mode 100644 index 000000000..1a45dd4cb Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Walk/Walk.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Walk/Walk.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Walk/Walk.ino new file mode 100644 index 000000000..61e2d9493 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/Walk/Walk.ino @@ -0,0 +1,34 @@ +/* +Grove LED Bar - Walk Example +This example will show you how to use setBits() function of this library. +Set any combination of LEDs using 10 bits. +This example walks through all 1024 (2^10) possible combinations. + +Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette +*/ + +#include + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar(35, 36, 0); // Clock pin, Data pin, Orientation + + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // 0 = 0x0 = all 10 LEDs turned off + // 1023 = 0x3FF = all 10 LEDs lit up + for (int i = 0; i <= 1023; i++) + { + bar.setBits(i); + delay(50); + } +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/WalkMultiple/WalkMultiple.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/WalkMultiple/WalkMultiple.ino new file mode 100644 index 000000000..0abb8bc6b --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/LP examples/WalkMultiple/WalkMultiple.ino @@ -0,0 +1,39 @@ +/* +Grove LED Bar - Walk Multiple Example +This example will show you how to use setBits() function of this library. +Set any combination of LEDs using 10 bits. +This example walks through all 1024 (2^10) possible combinations on two LED Bars. + +Ported for MSP-EXP430F5529, TM4c123 (Tiva C) LaunchPad By Cameron P. LaFollette +*/ + +#include + +// Arduino Clock pin, Data pin, Orientation +// Grove_LED_Bar bar1(9, 8, 0); // Clock pin, Data pin, Orientation +//Grove_LED_Bar bar2(7, 6, 1); // Clock pin, Data pin, Orientation + +// LaunchPad Clock pin, Data pin, Orientation +Grove_LED_Bar bar1(37, 38, 0); // Clock pin, Data pin, Orientation +Grove_LED_Bar bar2(35, 36, 0); // Clock pin, Data pin, Orientation + + + +void setup() +{ + // nothing to initialize + bar1.begin(); + bar2.begin(); +} + +void loop() +{ + // 0 = 0x0 = all 10 LEDs turned off + // 1023 = 0x3FF = all 10 LEDs lit up + for (int i = 0; i <= 1023; i++) + { + bar1.setBits(i); + bar2.setBits(i); + delay(50); + } +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/License.txt b/examples/osd/lgb-train/Grove_LED_Bar-master/License.txt new file mode 100644 index 000000000..baf484b44 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/License.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2013 Seeed Technology Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/README.md b/examples/osd/lgb-train/Grove_LED_Bar-master/README.md new file mode 100644 index 000000000..b268e558f --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/README.md @@ -0,0 +1,38 @@ +Grove LED Bar +------------------------------------------------------------- +![image](Grove_LED_Bar.gif) + + +Grove LED Bar is comprised of a 10 segment LED gauge bar and an MY9221 LED driver. +It can be used as a indicator for remaining battery life, voltage, water level, music volume or other values that require a gradient display. +There are 10 discrete LED bars in the LED bar graph: one red, one yellow, one light green, and the rest green. + + +For more information, please refer to the wiki: [Grove_LED_Bar][1] and [LED_Bar][2] + +SKU: [LED05031P][3] + + +---- + +This software is written by Frankie Chu for seeed studio
+and is licensed under [The MIT License](http://opensource.org/licenses/mit-license.php). Check License.txt for more information.
+ +Contributing to this software is warmly welcomed. You can do this basically by
+[forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
+for operating guide). Adding change log and your contact into file header is encouraged.
+Thanks for your contribution. + +Seeed Studio is an open hardware facilitation company based in Shenzhen, China.
+Benefiting from local manufacture power and convenient global logistic system,
+we integrate resources to serve new era of innovation. Seeed also works with
+global distributors and partners to push open hardware movement.
+ + +[1]:http://www.seeedstudio.com/wiki/Grove_-_LED_Bar + +[2]:http://www.seeedstudio.com/wiki/LED_Bar + +[3]:http://www.seeedstudio.com/depot/Grove-LED-Bar-p-1178.html + +[![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/Grove_LED_Bar)](https://github.com/igrigorik/ga-beacon) diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/BasicControl/BasicControl.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/BasicControl/BasicControl.gif new file mode 100644 index 000000000..b0770d1d8 Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/BasicControl/BasicControl.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/BasicControl/BasicControl.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/BasicControl/BasicControl.ino new file mode 100644 index 000000000..0d7902da2 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/BasicControl/BasicControl.ino @@ -0,0 +1,71 @@ +/* +Grove LED Bar - Basic Control Example +This example will show you how to use the setBits() function of this library. +Set any combination of LEDs using 10 bits. +Least significant bit controls the first LED. + +The setBits() function sets the current state, one bit for each LED. +First 10 bits from the right control the 10 LEDs. + +eg. 0b00000jihgfedcba +a = LED 1, b = LED 2, c = LED 3, etc. + +dec hex binary +0 = 0x0 = 0b000000000000000 = all LEDs off +5 = 0x05 = 0b000000000000101 = LEDs 1 and 3 on, all others off +341 = 0x155 = 0b000000101010101 = LEDs 1,3,5,7,9 on, 2,4,6,8,10 off +1023 = 0x3ff = 0b000001111111111 = all LEDs on + | | + 10 1 + +The bits >10 are ignored, shown here as x: 0bxxxxx0000000000 +*/ + +#include + +Grove_LED_Bar bar(7, 6, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Turn on all LEDs + bar.setBits(0x3ff); + delay(1000); + + // Turn off all LEDs + bar.setBits(0x0); + delay(1000); + + // Turn on LED 1 + // 0b000000000000001 can also be written as 0x1: + bar.setBits(0b000000000000001); + delay(1000); + + // Turn on LEDs 1 and 3 + // 0b000000000000101 can also be written as 0x5: + bar.setBits(0b000000000000101); + delay(1000); + + // Turn on LEDs 1, 3, 5, 7, 9 + bar.setBits(0x155); + delay(1000); + + // Turn on LEDs 2, 4, 6, 8, 10 + bar.setBits(0x2AA); + delay(1000); + + // Turn on LEDs 1, 2, 3, 4, 5 + // 0b000000000011111 == 0x1F + bar.setBits(0b000000000011111); + delay(1000); + + // Turn on LEDs 6, 7, 8, 9, 10 + // 0b000001111100000 == 0x3E0 + bar.setBits(0b000001111100000); + delay(1000); +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Bounce/Bounce.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Bounce/Bounce.gif new file mode 100644 index 000000000..ff3bfe01d Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Bounce/Bounce.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Bounce/Bounce.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Bounce/Bounce.ino new file mode 100644 index 000000000..7adf38e0c --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Bounce/Bounce.ino @@ -0,0 +1,45 @@ +/* +Grove LED Bar - Bounce Example +This example will show you how to use getBits() function of this library. +The getBits() function returns the current state so you can modify it. +Use the setBits() function to save the new state. +*/ + +#include + +Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +unsigned int state; + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Switch on the first two LEDs + bar.setLevel(2); + + // Get the current state (which is 0x3) + state = bar.getBits(); + + // Bounce to the right + for (int i = 0; i < 8; i++) + { + // Bit shift left and update + state <<= 1; + bar.setBits(state); + delay(200); + } + + // Bounce to the left + for (int i = 0; i < 8; i++) + { + // Bit shift right and update + state >>= 1; + bar.setBits(state); + delay(200); + } +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/ControlSingleLed/ControlSingleLed.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/ControlSingleLed/ControlSingleLed.gif new file mode 100644 index 000000000..01c8e96ba Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/ControlSingleLed/ControlSingleLed.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/ControlSingleLed/ControlSingleLed.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/ControlSingleLed/ControlSingleLed.ino new file mode 100644 index 000000000..9d3b60e31 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/ControlSingleLed/ControlSingleLed.ino @@ -0,0 +1,61 @@ +/* +Grove LED Bar - Control Single LED Example +This example will show you how to use the setLed() function of this library. +There are 10 LEDs in the Grove LED Bar. +Use this method to set a single LED. + +Syntax setLed(led, state) +led (1-10) +state (0=off, 1=on) +*/ + +#include + +Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Set LED 3 on + bar.setLed(3, 1); + delay(500); + + // Set LED 5 on + bar.setLed(5, 1); + delay(500); + + // Set LED 7 on + bar.setLed(7, 1); + delay(500); + + // Set LED 3 off + bar.setLed(3, 0); + delay(500); + + // Set LED 5 off + bar.setLed(5, 0); + delay(500); + + // Set LED 7 off + bar.setLed(7, 0); + delay(500); + + // Turn all LEDs on + for (int i = 1; i <= 10; i++) + { + bar.setLed(i, 1); + delay(500); + } + + // Turn all LEDs off + for (int i = 1; i <= 10; i++) + { + bar.setLed(i, 0); + delay(500); + } +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Level/Level.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Level/Level.gif new file mode 100644 index 000000000..f85eea136 Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Level/Level.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Level/Level.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Level/Level.ino new file mode 100644 index 000000000..1286cfba6 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Level/Level.ino @@ -0,0 +1,30 @@ +/* +Grove LED Bar - Level Example +This example will show you how to use setLevel() function of this library. +The setLevel() function illuminates the given number of LEDs from either side. + +Syntax setLevel(level) +0 = all LEDs off +5 = 5 LEDs on +10 = all LEDs on +*/ + +#include + +Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Walk through the levels + for (int i = 0; i <= 10; i++) + { + bar.setLevel(i); + delay(100); + } +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/README.md b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/README.md new file mode 100644 index 000000000..0ad2bdcd4 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/README.md @@ -0,0 +1,44 @@ +# Examples + +## BasicControl +![BasicControl](BasicControl/BasicControl.gif) + +---- + +## Bounce +![Bounce](Bounce/Bounce.gif) + +---- + +## ControlSingleLed +![ControlSingleLed](ControlSingleLed/ControlSingleLed.gif) + +---- + +## Level +![Level](Level/Level.gif) + +---- + +## Random +![Random](Random/Random.gif) + +---- + +## Reverse +![Reverse](Reverse/Reverse.gif) + +---- + +## Toggle +![Toggle](Toggle/Toggle.gif) + +---- + +## Walk +![Walk](Walk/Walk.gif) + +---- + +## WalkMultiple +Same as the Walk example, only with two Grove LED bars, the second initialised in reverse mode. diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Random/Random.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Random/Random.gif new file mode 100644 index 000000000..09b5fe72b Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Random/Random.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Random/Random.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Random/Random.ino new file mode 100644 index 000000000..8d79d93fa --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Random/Random.ino @@ -0,0 +1,22 @@ +/* +Grove LED Bar - Random Example +This example will show you how to use setBits() function of this library. +Set any combination of LEDs using 10 bits. +*/ + +#include + +Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Display a random value between 0 (all LEDs off) and 1023 (all LEDs on) + bar.setBits(random(1024)); + delay(50); +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Reverse/Reverse.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Reverse/Reverse.gif new file mode 100644 index 000000000..37fc0db4c Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Reverse/Reverse.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Reverse/Reverse.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Reverse/Reverse.ino new file mode 100644 index 000000000..44ac06519 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Reverse/Reverse.ino @@ -0,0 +1,59 @@ +/* +Grove LED Bar - Reverse Example +This example will show you how to use setGreenToRed() function of this library. +The function is used to reverse the orientation of the LED Bar. +*/ + +#include + +// The 3rd parameter sets the initial orientation +// 0 = green to red, 1 = red to green +// You can always change it at runtime with the setGreenToRed() function +Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Start as red to green + // Walk through the 10 levels + for (int i = 0; i <= 10; i++) + { + bar.setLevel(i); + delay(200); + } + bar.setLevel(0); + + // Swich to green to red + bar.setGreenToRed(1); + + // Walk through the 10 levels + for (int i = 0; i <= 10; i++) + { + bar.setLevel(i); + delay(200); + } + bar.setLevel(0); + + // Switch back to red to green + bar.setGreenToRed(0); + delay(200); + + // Walk through the levels + // Each reverse keeps the previously set level + for (int i = 1; i <= 10; i++) + { + bar.setLevel(i); + delay(500); + + bar.setGreenToRed(1); + delay(500); + + bar.setGreenToRed(0); + } + bar.setLevel(0); +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Toggle/Toggle.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Toggle/Toggle.gif new file mode 100644 index 000000000..33e47b338 Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Toggle/Toggle.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Toggle/Toggle.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Toggle/Toggle.ino new file mode 100644 index 000000000..6ae36560e --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Toggle/Toggle.ino @@ -0,0 +1,42 @@ +/* +Grove LED Bar - Toggle Example +This example will show you how to use toggleLed() function of this library. +The function lets you set a single led to the opposite of it's current value. +*/ + +#include + +Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Start with all LEDs illuminated + bar.setLevel(10); + delay(1000); + + // Turn off LED 3 + bar.toggleLed(3); + delay(1000); + + // Turn on LED 3 + bar.toggleLed(3); + delay(1000); + + // Switch off all LEDs + bar.setLevel(0); + delay(1000); + + // Turn on LED 7 + bar.toggleLed(7); + delay(1000); + + // Turn off LED 7 + bar.toggleLed(7); + delay(1000); +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/V3_ControlSingleLed/V3_ControlSingleLed.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/V3_ControlSingleLed/V3_ControlSingleLed.ino new file mode 100644 index 000000000..59329c855 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/V3_ControlSingleLed/V3_ControlSingleLed.ino @@ -0,0 +1,34 @@ +/* +Grove LED Bar - Control Single LED Example +... +*/ + +#include + +Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // Simulate police LED lights using setLed method + for (float i = 0; i < 1.1; i += .125f) { + bar.setLed(1, i); + bar.setLed(2, i); + bar.setLed(3, 1 - i); + bar.setLed(4, 1 - i); + delay(50); + }; + + for (float i = 0; i < 1.1; i += .125f) { + bar.setLed(1, 1 - i); + bar.setLed(2, 1 - i); + bar.setLed(3, i); + bar.setLed(4, i); + delay(50); + }; +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/V3_Level/V3_Level.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/V3_Level/V3_Level.ino new file mode 100644 index 000000000..bc036c8b2 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/V3_Level/V3_Level.ino @@ -0,0 +1,38 @@ +/* +Grove LED Bar - Brightness Level Example +... +*/ + +#include + +Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + bar.setGreenToRed(false); + for (float i = 0; i < 10.1; i += 0.125) { + bar.setLevel(i); + delay(25); + }; + for (float i = 0; i < 10.1; i += 0.125) { + bar.setLevel(10-i); + delay(25); + }; + + // Change orientation + bar.setGreenToRed(true); + for (float i = 0; i < 10.1; i += 0.125) { + bar.setLevel(i); + delay(25); + }; + for (float i = 0; i < 10.1; i += 0.125) { + bar.setLevel(10-i); + delay(25); + }; +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/V3_Wave/V3_Wave.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/V3_Wave/V3_Wave.ino new file mode 100644 index 000000000..60305bd74 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/V3_Wave/V3_Wave.ino @@ -0,0 +1,52 @@ +/* +Grove LED Bar - Wave Example +... +*/ + +#include + +Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +// Frames of continuous waves +unsigned char state[] = +{ + 0b11111111, + 0b01111111, + 0b00111111, + 0b00011111, + 0b00001111, + 0b00000111, + 0b00000011, + 0b00000001, + 0b00000000, + 0b00000001, + 0b00000011, + 0b00000111, + 0b00001111, + 0b00011111, + 0b00111111, + 0b01111111, + 0b11111111, + 0b01111111, + 0b00111111, + 0b00011111, + 0b00001111, + 0b00000111, + 0b00000011, + 0b00000001, + 0b00000000 +}; + +void loop() +{ + for (byte i = 0; i < (sizeof(state) - 9); i++) { + bar.setBits(state + i); + delay(50); + }; +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Walk/Walk.gif b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Walk/Walk.gif new file mode 100644 index 000000000..1a45dd4cb Binary files /dev/null and b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Walk/Walk.gif differ diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Walk/Walk.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Walk/Walk.ino new file mode 100644 index 000000000..a1a6eda6f --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/Walk/Walk.ino @@ -0,0 +1,27 @@ +/* +Grove LED Bar - Walk Example +This example will show you how to use setBits() function of this library. +Set any combination of LEDs using 10 bits. +This example walks through all 1024 (2^10) possible combinations. +*/ + +#include + +Grove_LED_Bar bar(9, 8, 0); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // 0 = 0x0 = all 10 LEDs turned off + // 1023 = 0x3FF = all 10 LEDs lit up + for (int i = 0; i <= 1023; i++) + { + bar.setBits(i); + delay(50); + } +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/examples/WalkMultiple/WalkMultiple.ino b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/WalkMultiple/WalkMultiple.ino new file mode 100644 index 000000000..d3b9e24fb --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/examples/WalkMultiple/WalkMultiple.ino @@ -0,0 +1,29 @@ +/* +Grove LED Bar - Walk Multiple Example +This example will show you how to use setBits() function of this library. +Set any combination of LEDs using 10 bits. +This example walks through all 1024 (2^10) possible combinations on two LED Bars. +*/ + +#include + +Grove_LED_Bar bar1(9, 8, 0); // Clock pin, Data pin, Orientation +Grove_LED_Bar bar2(7, 6, 1); // Clock pin, Data pin, Orientation + +void setup() +{ + // nothing to initialize + bar.begin(); +} + +void loop() +{ + // 0 = 0x0 = all 10 LEDs turned off + // 1023 = 0x3FF = all 10 LEDs lit up + for (int i = 0; i <= 1023; i++) + { + bar1.setBits(i); + bar2.setBits(i); + delay(50); + } +} diff --git a/examples/osd/lgb-train/Grove_LED_Bar-master/keywords.txt b/examples/osd/lgb-train/Grove_LED_Bar-master/keywords.txt new file mode 100644 index 000000000..64896e9a1 --- /dev/null +++ b/examples/osd/lgb-train/Grove_LED_Bar-master/keywords.txt @@ -0,0 +1,8 @@ +Grove_LED_Bar KEYWORD1 + +setGreenToRed KEYWORD2 +setLevel KEYWORD2 +setLed KEYWORD2 +toggleLed KEYWORD2 +setBits KEYWORD2 +getBits KEYWORD2 diff --git a/examples/osd/lgb-train/Joystick/demo.ino b/examples/osd/lgb-train/Joystick/demo.ino new file mode 100644 index 000000000..4b4e858ed --- /dev/null +++ b/examples/osd/lgb-train/Joystick/demo.ino @@ -0,0 +1,23 @@ +/* + Thumb Joystick demo v1.0 + by:http://www.seeedstudio.com + connect the module to A0&A1 for using; +*/ + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + int sensorValue1 = analogRead(A0); + int sensorValue2 = analogRead(A1); + + Serial.print("The X and Y coordinate is:"); + Serial.print(sensorValue1, DEC); + Serial.print(","); + Serial.println(sensorValue2, DEC); + Serial.println(" "); + delay(200); +} diff --git a/examples/osd/lgb-train/Makefile b/examples/osd/lgb-train/Makefile new file mode 100644 index 000000000..5a017eac0 --- /dev/null +++ b/examples/osd/lgb-train/Makefile @@ -0,0 +1,70 @@ +# Set this to the name of your sketch (without extension .pde) +SKETCH=sketch +EXE=arduino-example + +all: $(EXE) + +CONTIKI=../../.. + +# Contiki IPv6 configuration +CONTIKI_WITH_IPV6 = 1 + +CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\" + +PROJECT_SOURCEFILES += ${SKETCH}.cpp + +# automatically build RESTful resources +REST_RESOURCES_DIR = ./resources +REST_RESOURCES_DIR_COMMON = ../resources-common +REST_RESOURCES_FILES= $(notdir \ + $(shell find $(REST_RESOURCES_DIR) -name '*.c') \ + $(shell find $(REST_RESOURCES_DIR_COMMON) -name '*.c') \ + ) + +PROJECTDIRS += $(REST_RESOURCES_DIR) $(REST_RESOURCES_DIR_COMMON) +PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES) + +# variable for Makefile.include +ifneq ($(TARGET), minimal-net) +CFLAGS += -DUIP_CONF_IPV6_RPL=1 +else +# minimal-net does not support RPL under Linux and is mostly used to test CoAP only +${info INFO: compiling without RPL} +CFLAGS += -DUIP_CONF_IPV6_RPL=0 +CFLAGS += -DHARD_CODED_ADDRESS=\"fdfd::10\" +${info INFO: compiling with large buffers} +CFLAGS += -DUIP_CONF_BUFFER_SIZE=2048 +CFLAGS += -DREST_MAX_CHUNK_SIZE=1024 +CFLAGS += -DCOAP_MAX_HEADER_SIZE=640 +endif + +# linker optimizations +SMALL=1 + + +# REST Engine shall use Erbium CoAP implementation +APPS += er-coap +APPS += rest-engine +APPS += arduino + +include $(CONTIKI)/Makefile.include +include $(CONTIKI)/apps/arduino/Makefile.include + +$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c + (cd $(CONTIKI)/tools && $(MAKE) tunslip6) + +connect-router: $(CONTIKI)/tools/tunslip6 + sudo $(CONTIKI)/tools/tunslip6 aaaa::1/64 + +connect-router-cooja: $(CONTIKI)/tools/tunslip6 + sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 aaaa::1/64 + +connect-minimal: + sudo ip address add fdfd::1/64 dev tap0 + +avr-size: $(EXE).$(TARGET).sz + +flash: $(EXE).$(TARGET).u $(EXE).$(TARGET).eu + +.PHONY: flash avr-size +.PRECIOUS: $(EXE).$(TARGET).hex $(EXE).$(TARGET).eep diff --git a/examples/osd/lgb-train/README.md b/examples/osd/lgb-train/README.md new file mode 100644 index 000000000..e1490ed05 --- /dev/null +++ b/examples/osd/lgb-train/README.md @@ -0,0 +1,11 @@ +Arduino compatibility example +============================= + +This example shows that it is now possible to re-use arduino sketches in +Contiki. This example documents the necessary magic. Arduino specifies +two routines, `setup` and `loop`. Before `setup` is called, the +framework initializes hardware. In original Arduino, all this is done in +a `main` function (in C). For contiki we define a process that does the +same. + +See the documentation file in apps/contiki-compat/README.md diff --git a/examples/osd/lgb-train/arduino-example.c b/examples/osd/lgb-train/arduino-example.c new file mode 100644 index 000000000..ea74dd8b8 --- /dev/null +++ b/examples/osd/lgb-train/arduino-example.c @@ -0,0 +1,2 @@ +#include +AUTOSTART_PROCESSES(&arduino_sketch); diff --git a/examples/osd/lgb-train/arduino-merkurbaord.geany b/examples/osd/lgb-train/arduino-merkurbaord.geany new file mode 100644 index 000000000..8a57b7973 --- /dev/null +++ b/examples/osd/lgb-train/arduino-merkurbaord.geany @@ -0,0 +1,64 @@ +[file_prefs] +final_new_line=true +ensure_convert_new_lines=false +strip_trailing_spaces=false +replace_tabs=false + +[indentation] +indent_width=4 +indent_type=1 +indent_hard_tab_width=8 +detect_indent=false +detect_indent_width=false +indent_mode=2 + +[project] +name=arduino-merkurbaord +base_path=/home/harald/install/osd-contiki/examples/osd/arduino-merkurboard/ +description= +file_patterns= + +[long line marker] +long_line_behaviour=1 +long_line_column=72 + +[files] +current_page=11 +FILE_NAME_0=2281;None;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2Fsketch.pde;0;4 +FILE_NAME_1=2895;C;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2Fresources%2Fres-soillight.c;0;4 +FILE_NAME_2=2893;C;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2Fresources%2Fres-soiltemp.c;0;4 +FILE_NAME_3=2177;C;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2Fproject-conf.h;0;4 +FILE_NAME_4=5823;C++;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2FI2CSoilMoistureSensor.cpp;0;4 +FILE_NAME_5=1931;C;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fosd-contiki%2Fexamples%2Fosd%2Farduino-soil-moisture%2FI2CSoilMoistureSensor.h;0;4 +FILE_NAME_6=0;None;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fsunrise%2FPCTools%2Fpowerconsumption%2FPICOTEST%2Ftemplate%2Fvob-ok%2Faverage2.awk;0;4 +FILE_NAME_7=0;XML;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Fprojekte%2Fairkey-ez2092%2FEZ2092.sch;0;4 +FILE_NAME_8=0;HTML;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2FDownloads%2FSemesterplan.html;0;4 +FILE_NAME_9=1273;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Finstall%2Fpensi%2Fpensi.sh;0;4 +FILE_NAME_10=600;None;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Fprojekte%2Fairkey-commissioningtest%2FREADME;0;4 +FILE_NAME_11=139;Sh;0;EUTF-8;1;1;0;%2Fhome%2Fharald%2Fprojekte%2Fairkey-energieverbrauch%2Fpowerconsumption%2FPICOTEST%2Fez2092b%2Fez2092a-fw4.54%2Fstartup%2Fmessung.sh;0;4 + +[VTE] +last_dir=/home/harald + +[build-menu] +NF_00_LB=_Make +NF_00_CM=make TARGET=osd-merkur-256 +NF_00_WD= +NF_01_LB=Make flash +NF_01_CM=make TARGET=osd-merkur-256 flash +NF_01_WD= +NF_03_LB=Make Clean +NF_03_CM=make clean TARGET=osd-merkur-256 +NF_03_WD= +C++FT_00_LB=_Kompilieren +C++FT_00_CM=make TARGET=osd-merkur-256 +C++FT_00_WD= +C++FT_01_LB=_Erstellen +C++FT_01_CM=make TARGET=osd-merkur-256 flash +C++FT_01_WD= +filetypes=C++; + +[editor] +line_wrapping=false +line_break_column=72 +auto_continue_multiline=true diff --git a/examples/osd/lgb-train/flash.sh b/examples/osd/lgb-train/flash.sh new file mode 100755 index 000000000..e82962073 --- /dev/null +++ b/examples/osd/lgb-train/flash.sh @@ -0,0 +1,2 @@ +#!/bin/bash +make TARGET=osd-merkur-128 flash diff --git a/examples/osd/lgb-train/project-conf.h b/examples/osd/lgb-train/project-conf.h new file mode 100644 index 000000000..957c568ad --- /dev/null +++ b/examples/osd/lgb-train/project-conf.h @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2010, Swedish Institute of Computer Science. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * + */ + +#ifndef PROJECT_RPL_WEB_CONF_H_ +#define PROJECT_RPL_WEB_CONF_H_ + +#define PLATFORM_HAS_LEDS 1 +//#define PLATFORM_HAS_BUTTON 1 +#define PLATFORM_HAS_BATTERY 1 + + +#define LOOP_INTERVAL (30 * CLOCK_SECOND) + +/* Save energy */ +//#define RDC_CONF_PT_YIELD_OFF + +/* For Debug: Dont allow MCU sleeping between channel checks */ +//#undef RDC_CONF_MCU_SLEEP +//#define RDC_CONF_MCU_SLEEP 0 + +/* Disabling RDC for demo purposes. Core updates often require more memory. */ +/* For projects, optimize memory and enable RDC again. */ +//#undef NETSTACK_CONF_RDC +//#define NETSTACK_CONF_RDC nullrdc_driver +//#undef NETSTACK_CONF_MAC +//#define NETSTACK_CONF_MAC nullmac_driver + +/* Increase rpl-border-router IP-buffer when using more than 64. */ +//#undef REST_MAX_CHUNK_SIZE +//#define REST_MAX_CHUNK_SIZE 64 + +/* Estimate your header size, especially when using Proxy-Uri. */ +/* +#undef COAP_MAX_HEADER_SIZE +#define COAP_MAX_HEADER_SIZE 70 +*/ + +/* The IP buffer size must fit all other hops, in particular the border router. */ + +#undef UIP_CONF_BUFFER_SIZE +#define UIP_CONF_BUFFER_SIZE 256 + + +/* Multiplies with chunk size, be aware of memory constraints. */ +#undef COAP_MAX_OPEN_TRANSACTIONS +#define COAP_MAX_OPEN_TRANSACTIONS 4 + +/* Must be <= open transaction number, default is COAP_MAX_OPEN_TRANSACTIONS-1. */ +/* +#undef COAP_MAX_OBSERVERS +#define COAP_MAX_OBSERVERS 2 +*/ + +/* Filtering .well-known/core per query can be disabled to save space. */ +/* +#undef COAP_LINK_FORMAT_FILTERING +#define COAP_LINK_FORMAT_FILTERING 0 +*/ + + +#endif /* PROJECT_RPL_WEB_CONF_H_ */ diff --git a/examples/osd/lgb-train/resources/res-led.c b/examples/osd/lgb-train/resources/res-led.c new file mode 100644 index 000000000..fb0fa138f --- /dev/null +++ b/examples/osd/lgb-train/resources/res-led.c @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2013, Institute for Pervasive Computing, ETH Zurich + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the Institute nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * This file is part of the Contiki operating system. + */ + +/** + * \file + * Door resource + * \author + * Harald Pichler + */ + +#include "contiki.h" + +#include +#include "rest-engine.h" +#include "Arduino.h" + +static void res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); +static void res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset); + +/* A simple getter example. Returns the reading from the sensor with a simple etag */ +RESOURCE(res_led, + "title=\"LED: , POST/PUT mode=on|off\";rt=\"Control\"", + res_get_handler, + res_post_put_handler, + res_post_put_handler, + NULL); + +extern uint8_t led_pin; +extern uint8_t led_status; + +static void +res_get_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + unsigned int accept = -1; + REST.get_header_accept(request, &accept); + + if(accept == -1 || accept == REST.type.TEXT_PLAIN) { + REST.set_header_content_type(response, REST.type.TEXT_PLAIN); + snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "%d", led_status); + + REST.set_response_payload(response, buffer, strlen((char *)buffer)); + } else if(accept == REST.type.APPLICATION_JSON) { + REST.set_header_content_type(response, REST.type.APPLICATION_JSON); + snprintf((char *)buffer, REST_MAX_CHUNK_SIZE, "{'led':%d}", led_status); + + REST.set_response_payload(response, buffer, strlen((char *)buffer)); + } else { + REST.set_response_status(response, REST.status.NOT_ACCEPTABLE); + const char *msg = "Supporting content-types text/plain and application/json"; + REST.set_response_payload(response, msg, strlen(msg)); + } +} + +static void +res_post_put_handler(void *request, void *response, uint8_t *buffer, uint16_t preferred_size, int32_t *offset) +{ + size_t len = 0; + const char *mode = NULL; + int success = 1; + + if(success && (len = REST.get_post_variable(request, "mode", &mode))) { + if(strncmp(mode, "on", len) == 0) { + digitalWrite(led_pin, LOW); + led_status=1; + } else if(strncmp(mode, "off", len) == 0) { + digitalWrite(led_pin, HIGH); + led_status=0; + } else { + success = 0; + } + } else { + success = 0; + } if(!success) { + REST.set_response_status(response, REST.status.BAD_REQUEST); + } +} diff --git a/examples/osd/lgb-train/run.sh b/examples/osd/lgb-train/run.sh new file mode 100755 index 000000000..5d5cbbbb4 --- /dev/null +++ b/examples/osd/lgb-train/run.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# For the ages-old bootloader (before 2014) you want to use +# BOOTLOADER_GET_MAC=0x0001f3a0 as parameter to make below. +make clean TARGET=osd-merkur-128 +make TARGET=osd-merkur-128 diff --git a/examples/osd/lgb-train/sketch.pde b/examples/osd/lgb-train/sketch.pde new file mode 100644 index 000000000..337949c84 --- /dev/null +++ b/examples/osd/lgb-train/sketch.pde @@ -0,0 +1,44 @@ +/* + * Sample arduino sketch using contiki features. + * We turn the LED off + * We allow read the moisture sensor + * Unfortunately sleeping for long times in loop() isn't currently + * possible, something turns off the CPU (including PWM outputs) if a + * Proto-Thread is taking too long. We need to find out how to sleep in + * a Contiki-compatible way. + * Note that for a normal arduino sketch you won't have to include any + * of the contiki-specific files here, the sketch should just work. + */ + +extern "C" { +#include "arduino-process.h" +#include "rest-engine.h" +#include "net/netstack.h" + +extern resource_t res_led, res_battery, res_cputemp; + +uint8_t led_pin=4; +uint8_t led_status; +} + +void setup (void) +{ + // switch off the led + pinMode(led_pin, OUTPUT); + digitalWrite(led_pin, HIGH); + led_status=0; + // init coap resourcen + rest_init_engine (); + rest_activate_resource (&res_led, "s/led"); + rest_activate_resource (&res_battery, "s/battery"); + rest_activate_resource (&res_cputemp, "s/cputemp"); + + // NETSTACK_MAC.off(1); + mcu_sleep_set(128); +} + +void loop (void) +{ + + +}