From 5ddea026525baa699537a84f2b5b85c2b04035d5 Mon Sep 17 00:00:00 2001 From: mitchellhansen Date: Tue, 11 Feb 2020 16:43:09 -0800 Subject: [PATCH] . --- CMakeLists.txt | 26 ++- arduino/libraries/SoftPWM/.SoftPWM.cpp.swp | Bin 28672 -> 0 bytes arduino/libraries/SoftPWM/.SoftPWM.h.swp | Bin 12288 -> 0 bytes .../libraries/SoftPWM/.SoftPWM_timer.h.swp | Bin 12288 -> 0 bytes arduino/libraries/SoftPWM/LICENSE.txt | 20 --- arduino/libraries/SoftPWM/README.md | 137 -------------- arduino/libraries/SoftPWM/SoftPWM.cpp | 98 ++++------ arduino/libraries/SoftPWM/SoftPWM.h | 2 - arduino/libraries/SoftPWM/changelog.txt | 13 -- .../SoftPWM_Arduino_LED_Blink.pde | 18 -- .../SoftPWM_LEDHead_Bounce.pde | 38 ---- .../SoftPWM_LEDHead_Bounce2.pde | 43 ----- .../SoftPWM_LEDHead_Random_Blink.pde | 24 --- .../SoftPWM_Wiring_HeartBeat.pde | 30 ---- arduino/libraries/SoftPWM/keywords.txt | 36 ---- arduino/libraries/SoftPWM/library.properties | 9 - dozer_main.cpp | 102 +++++++++++ main.cpp | 169 ------------------ remote_main.cpp | 81 +++++++++ 19 files changed, 237 insertions(+), 609 deletions(-) delete mode 100644 arduino/libraries/SoftPWM/.SoftPWM.cpp.swp delete mode 100644 arduino/libraries/SoftPWM/.SoftPWM.h.swp delete mode 100644 arduino/libraries/SoftPWM/.SoftPWM_timer.h.swp delete mode 100644 arduino/libraries/SoftPWM/LICENSE.txt delete mode 100644 arduino/libraries/SoftPWM/README.md delete mode 100644 arduino/libraries/SoftPWM/changelog.txt delete mode 100644 arduino/libraries/SoftPWM/examples/SoftPWM_Arduino_LED_Blink/SoftPWM_Arduino_LED_Blink.pde delete mode 100644 arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Bounce/SoftPWM_LEDHead_Bounce.pde delete mode 100644 arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Bounce2/SoftPWM_LEDHead_Bounce2.pde delete mode 100644 arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Random_Blink/SoftPWM_LEDHead_Random_Blink.pde delete mode 100644 arduino/libraries/SoftPWM/examples/SoftPWM_Wiring_HeartBeat/SoftPWM_Wiring_HeartBeat.pde delete mode 100644 arduino/libraries/SoftPWM/keywords.txt delete mode 100644 arduino/libraries/SoftPWM/library.properties create mode 100644 dozer_main.cpp delete mode 100644 main.cpp create mode 100644 remote_main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fcce61..7bbd515 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,11 @@ project(battletank) cmake_minimum_required(VERSION 2.6) +set(REMOTE_PORT "/dev/ttyUSB0") +set(DOZER_PORT "/dev/ttyUSB1") + set(MCU "atmega328p" ) set(CPU_SPEED "16000000" ) -set(PORT "/dev/ttyUSB0") set(PORT_SPEED "57600") set(PIN_VARIANT "standard") set(ARDUINO_PATH "arduino") @@ -14,7 +16,8 @@ set(COMPILE_FLAGS "") # Set own source files # Simply list all your C / C++ source (not header!) files here -set(SRC_FILES main.cpp) +set(REMOTE_SRC_FILES remote_main.cpp) +set(DOZER_SRC_FILES dozer_main.cpp) # Include directories include_directories( @@ -55,10 +58,17 @@ set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") set(CMAKE_EXE_LINKER_FLAGS "-Os -Wl,--gc-sections -mmcu=${MCU}") -add_executable(${PROJECT_NAME} ${ARDUINO_CORE_SRC} ${SRC_FILES}) +add_executable(${PROJECT_NAME}-dozer ${ARDUINO_CORE_SRC} ${DOZER_SRC_FILES}) +add_executable(${PROJECT_NAME}-remote ${ARDUINO_CORE_SRC} ${REMOTE_SRC_FILES}) + +add_custom_target(flash-dozer + COMMAND ${CMAKE_OBJCOPY} -j .text -j .data -O ihex ${PROJECT_NAME}-dozer main.hex + COMMAND avrdude -F -p${MCU} -carduino -P${DOZER_PORT} -b${PORT_SPEED} -D -Uflash:w:main.hex:i + DEPENDS ${PROJECT_NAME}-dozer +) -add_custom_target(flash - COMMAND ${CMAKE_OBJCOPY} -j .text -j .data -O ihex ${PROJECT_NAME} main.hex - COMMAND avrdude -F -p${MCU} -carduino -P${PORT} -b${PORT_SPEED} -D -Uflash:w:main.hex:i - DEPENDS ${PROJECT_NAME} - ) +add_custom_target(flash-remote + COMMAND ${CMAKE_OBJCOPY} -j .text -j .data -O ihex ${PROJECT_NAME}-remote main.hex + COMMAND avrdude -F -p${MCU} -carduino -P${REMOTE_PORT} -b${PORT_SPEED} -D -Uflash:w:main.hex:i + DEPENDS ${PROJECT_NAME}-remote +) \ No newline at end of file diff --git a/arduino/libraries/SoftPWM/.SoftPWM.cpp.swp b/arduino/libraries/SoftPWM/.SoftPWM.cpp.swp deleted file mode 100644 index e293b12a93941e901cca60142dca0da54a9e176e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 28672 zcmeI43y>Ved4LDU;KZ1i7?T3xxY|;J_N2SLy#vVy(kWU_hqdNj+(U{AOUvx;?CnUq zGn?7jJDnwAs7m5s0wIsW22&2HRGc!Dolpk+ipx-b1cM8cIFbv;dEz9MkdT;^`eq5-s`S9Ro5&vhE1>3v>kV7Bt4cM8>-q)^Vp6nJMRux z?Sf}|w$&J3aLfMOf$8WoU94}M*@h)a9wriag-M|4mxsnKFs>LK(OrG>rnjhz-mvrv z6GBqmL;{Hf5(y*{NF(uNSO`DQ>H2(i_G1QG@H2XTUika^@beG4p8rVr`>o-p5k`#SN4JyDL;{Hf5(y*{NF4#ot*`^O!;2VOz64Lgt?(`wfNx@?`4l_|6*vs%!BZGl z-UoNU?QjDuz?VDn)q5^+~5y^q$3TC8~Npr<# zD4FCN3PSm=lAn&Xs&uR{(#h~s_0FTM48#nxi=(t6E3PPj8t}~Rh6u= z*{u4a)<>E(I@j`g4UcnbHR2hvQhn4VQm3e^>24-PF&$k5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raries/SoftPWM/.SoftPWM.h.swp deleted file mode 100644 index f7d30278df1ad0ffc0b48342ef23b1f696cf2a1c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2O>Y}T7{{kQ@m44xA;bYaB?po!S=%W@rb#P1jiW?zoD%1y2ShdA9oqxz88bU; z$5H?Z4jlOaw0sjJE_?uvNK^uDMZLg*3qs<*>$U5|N#P2aQT|%(JkLBYzZqMyGL8KH z<`xybJj1xm*sHHBz5o41%idgOtYg~A>^~0pEd(O^(CY3JeLsO?ZcX=9sCf|OxCvsZ z^g_Wadc}oMs`zl}t>d$~P&N!VQbf7BZra-iTcfAG z;|jg}(%$)M-*xKiRidJX#F8OFYZ40Hwh6@5O0eu0vn ze}dd_1RMcJz!7i+905n*|3zR%s6aLu>uDKKc8jtu>}?(5Vx=9-N@a_8Ep?@uC)~#z zzGTL^<&(?Sc_4OWM@%g%EFnk}*1c|GAI2I_CbvG5=@S7fDwqg#!k82(j4za(@R_J_ zXnQ=-#)Z;ISh_*^=}4!B=8mBZ*JG9kjI!dZy-ujp__4&8;o7e zv7;mWQK=_PB(zay5{uMb*t)m0G>x*+ZN`847A@11}j-*XR#~ zZ@sLvnIvRd`4P2*5{6qrahI$Hur#~h=1Pe$qS=9t4RsKWw*+bQBWXy=oK*|>WeVU zGWj|V18Sh-fOoA3l3KF}fMI$X3sgWFNeqR$Pfa5}iiPqA!+u7|f^p$}B+y3UNb@ip z5Uy^^mO|hJ+NidKYEpIser>Bnge6U?R@S0hf6!m`Z@_8`-t^j9@{srWBiyCPr4l>DkY4KGsNDW{JnPjr|*q$x3PEQ~)OC9%t-oX5!M92PJ#vEMuLZty=%_fZbR_glp3CZ)tlOhUqzP z!*x8~2-7@hbZyrgGg6bO$uY-vyPFfa-K}ZIt_M7@MVPL7O}Ttwv45^fyCZ_s?FD$t zsPs*(zmKr5gX&drfj#HmPkqt~Xa%$aS^=$qRzNGD70?Q31+)TM0j+>m;2uhMDY0k|Nh_qe?G?8=ip6H2Q^Rz;~)i&fy3Ys`1BZKpMYy%3tR#(f)bbq1uzRz z-~>1hzC8;6AOv&Zk4G8%1$+a(2G_xR;B`<2PlDf$F!mLA11x|Wk1+N&cngGJ8XN)N zA7<=B@G_VOKRnFX``}%08I-^i;OB?%Jn$L#2z&spf-7JREP-=i6#R6EvG2fj@CEo7 zyaOay0KY@OU%?F!X?YLM1s$?hKr8USR$xT94ZF!+OEMxkHeDAj+f9V{w94P;)NEIZ zV4XYhw^gUe$V5jfLupDh@zIt{CaUFm6Q5z#<}1bLX_T_3Cz8ptbP?`Kz22t!FpEYd zJxi|G*xj6nY)2ZRX}f~@zRc2Mu~I87mCS@^1xZT0dXepKQ!Sba1ehG$E>$auW|G!D zyFtx_I^kYC#*waz=MXH|h}|4q{>`(^Vx_XOY!Z(B<$znqZc^O6kyxn~5ixqL=Fdm* zCu31@T|Jj03_fAd)D)EqrD87Mlc-#%0c6YX}-mtIR|$^ZgF{D|;vEE0HK+7M9E$oJI-R$;jTM4hb9Sl&clW zi_7`iy0GLvn)YlKs>6C_)nf*7W|f>6rEq!O5fpt0m?f_({jMa->-ann)Zx-iM-a2TnvI8n?iRugh6deqcq{I9H}PkQz?lAayTxG|7N zEg)kyN!vp+!1#AF!1&K*fH6zk{k&od7;$QDH?f#PaDe{(iD6`R#$BkwTa@WLao1b* zH&4U6IU%BC-PwdNc1?&qbv3F1Mv|q|)KsgEVPmrZ$}6ouO9aL8n$r(#ey9-NGyum#Qz!t(2C^JBwxzP_DL69eQLI8?M8xwXj#( zPEj3&O$E`mTWuAIXvDX2@#BZ&tJU(Wm0I5Hh!!8uuH+Dhk`cN_7PR3>Hg z8&T3wFDWlO!XZRQlQe6~$X;&wg3d>ucyCeI^?fghZ@9dJ*8{wkY^Yj}_lPDZg)cQB3$0-U@7Ab?G^t=?2bVqrpX6O8-ncy Include Library -> Manage Libraries...) to download the library. - -Alternatively, you can download the library directly, and install it yourself. - -* [SoftPWM Library - Latest Version](https://github.com/bhagman/SoftPWM/archive/master.zip) - -Unzip the folder and rename it to `SoftPWM`, then move it to your `arduinosketchfolder/libraries/` folder. - ----- - -## Usage Example ## - -``` -#include "SoftPWM.h" - -void setup() -{ - // Initialize - SoftPWMBegin(); - - // Create and set pin 13 to 0 (off) - SoftPWMSet(13, 0); - - // Set fade time for pin 13 to 100 ms fade-up time, and 500 ms fade-down time - SoftPWMSetFadeTime(13, 100, 500); -} - -void loop() -{ - // Turn on - set to 100% - SoftPWMSetPercent(13, 100); - - // Wait for LED to turn on - you could do other tasks here - delay(100); - - // Turn off - set to 0% - SoftPWMSetPercent(13, 0); - - // Wait for LED to turn off - delay(500); -} -``` - ----- -## Function Descriptions ## - -`SoftPWMBegin([defaultPolarity])` - -* Initializes the library - sets up the timer and other tasks. -* optional `defaultPolarity` allows all newly defined pins to take on this polarity. - * Values: `SOFTPWM_NORMAL`, `SOFTPWM_INVERTED` - -`SoftPWMSet(pin,value)` - -* `pin` is the output pin. -* `value` is a value between 0 and 255 (inclusive). - -`SoftPWMSetPercent(pin,percent)` - -* `pin` is the output pin. -* `percent` is a value between 0 and 100 (inclusive). - -`SoftPWMSetFadeTime(pin,fadeUpTime,fadeDownTime)` - -* `pin` is the output pin. -* `fadeuptime` is the time in milliseconds that it will take the channel to fade from 0 to 255. - * Range: 0 to 4000 -* `fadedowntime` is the time in milliseconds that it will take the channel to fade from 255 to 0. - * Range: 0 to 4000 - -`SoftPWMSetPolarity(pin,polarity)` - -* `pin` is the output pin. -* `polarity` is the polarity for the given pin. - -### Notes ### - -* You can use `ALL` in place of the pin number to have the function act on all currently set channels. - * e.g. `SoftPWMSetFadeTime(ALL, 100, 400)` - this will set all created channels to have a fade-up time of 100 ms and a fade-down time of 400. -* The polarity setting of the pin is as follows: - * `SOFTPWM_NORMAL` means that the pin is LOW when the PWM value is 0, whereas `SOFTPWM_INVERTED` indicates the pin should be HIGH when the PWM value is 0. - - ----- - -## Demonstrations ## - -Arduino Duemilanove LED Blink example - available as library example: - -[![Arduino SoftPWM example](https://img.youtube.com/vi/9tTd7aLm9aQ/0.jpg)](https://www.youtube.com/watch?v=9tTd7aLm9aQ) - -rDuino LEDHead Bounce example - available as library example: - -[![rDuino LEDHead SoftPWM example](https://img.youtube.com/vi/jE7Zw1zNL6c/0.jpg)](https://www.youtube.com/watch?v=jE7Zw1zNL6c) - -More demos: - -https://www.youtube.com/view_play_list?p=33BB5D2E20609C52 - ----- diff --git a/arduino/libraries/SoftPWM/SoftPWM.cpp b/arduino/libraries/SoftPWM/SoftPWM.cpp index 7949fd5..c254c21 100644 --- a/arduino/libraries/SoftPWM/SoftPWM.cpp +++ b/arduino/libraries/SoftPWM/SoftPWM.cpp @@ -96,42 +96,24 @@ ISR(TIMER1_COMPA_vect) // set all channels high - let's start again // and accept new checkvals for (i = 0; i < SOFTPWM_MAXCHANNELS; i++) { - if (_softpwm_channels[i].fadeuprate > 0 || _softpwm_channels[i].fadedownrate > 0) { - // we want to fade to the new value - direction = _softpwm_channels[i].pwmvalue - _softpwm_channels[i].checkval; - - // we will default to jumping to the new value - newvalue = _softpwm_channels[i].pwmvalue; - - if (direction > 0 && _softpwm_channels[i].fadeuprate > 0) { - newvalue = _softpwm_channels[i].checkval + _softpwm_channels[i].fadeuprate; - if (newvalue > _softpwm_channels[i].pwmvalue) - newvalue = _softpwm_channels[i].pwmvalue; - } else if (direction < 0 && _softpwm_channels[i].fadedownrate > 0) { - newvalue = _softpwm_channels[i].checkval - _softpwm_channels[i].fadedownrate; - if (newvalue < _softpwm_channels[i].pwmvalue) - newvalue = _softpwm_channels[i].pwmvalue; - } - - _softpwm_channels[i].checkval = newvalue; - } else // just set the channel to the new value - _softpwm_channels[i].checkval = _softpwm_channels[i].pwmvalue; + + // check on pwm, 0-255 + _softpwm_channels[i].checkval = _softpwm_channels[i].pwmvalue; // now set the pin high (if not 0) - if (_softpwm_channels[i].checkval > 0) // don't set if checkval == 0 + if (_softpwm_channels[i].checkval > 0) { if (_softpwm_channels[i].polarity == SOFTPWM_NORMAL) *_softpwm_channels[i].outport |= _softpwm_channels[i].pinmask; else *_softpwm_channels[i].outport &= ~(_softpwm_channels[i].pinmask); } - } } for (i = 0; i < SOFTPWM_MAXCHANNELS; i++) { - if (_softpwm_channels[i].pin >= 0) // if it's a valid pin + if (_softpwm_channels[i].pin >= 0) // Only set un-flagged pins { if (_softpwm_channels[i].checkval == _isr_softcount) // if we have hit the width { @@ -154,32 +136,17 @@ void SoftPWMBegin(uint8_t defaultPolarity) { // At these settings on a 16 MHz part, we will get a PWM period of // approximately 60Hz (~16ms). - uint8_t i; - -//#ifdef WIRING -// Timer2.setMode(0b010); // CTC -// Timer2.setClockSource(CLOCK_PRESCALE_8); -// Timer2.setOCR(CHANNEL_A, SOFTPWM_OCR); -// Timer2.attachInterrupt(INTERRUPT_COMPARE_MATCH_A, SoftPWM_Timer_Interrupt); -//#else -// SOFTPWM_TIMER_INIT(SOFTPWM_OCR); -//#endif - - cli(); //Disable interrupts while setting registers - TCCR1A = 0; // Make sure it is zero - TCCR1B = 0; // Make sure it is zero - //TCCR1B = (1 << WGM21); // Configure for CTC mode (Set it; don't OR stuff into it) - //TCCR1B |= (1 << CS21); // Prescaler @ 1024 + // Hand init + cli(); // Disable interrupts while setting registers + TCCR1A = 0; // Reset the timer + TCCR1B = 0; // Reset the timer TIMSK1 = (1 << OCIE1A); // Enable interrupt - OCR1A = SOFTPWM_OCR; // compare value = 1 sec (16MHz AVR) - TCCR1B = (1 << CS21); /* start timer (ck/8 prescalar) */ \ TCCR1A = (1 << WGM21); /* CTC mode */ \ - + OCR1A = SOFTPWM_OCR; // compare value sei(); - - for (i = 0; i < SOFTPWM_MAXCHANNELS; i++) { + for (uint8_t i = 0; i < SOFTPWM_MAXCHANNELS; i++) { _softpwm_channels[i].pin = -1; _softpwm_channels[i].polarity = SOFTPWM_NORMAL; _softpwm_channels[i].outport = 0; @@ -207,24 +174,20 @@ void SoftPWMSetPolarity(int8_t pin, uint8_t polarity) { } -void SoftPWMSetPercent(int8_t pin, uint8_t percent, uint8_t hardset) { - SoftPWMSet(pin, ((uint16_t) percent * 255) / 100, hardset); -} +void SoftPWMSet(uint8_t pin, uint8_t value, uint8_t hardset) { -void SoftPWMSet(int8_t pin, uint8_t value, uint8_t hardset) { - int8_t firstfree = -1; // first free index - uint8_t i; if (hardset) { SOFTPWM_TIMER_SET(0); _isr_softcount = 0xff; } + int8_t firstfree = -1; // first free index + // If the pin isn't already set, add it - for (i = 0; i < SOFTPWM_MAXCHANNELS; i++) { - if ((pin < 0 && _softpwm_channels[i].pin >= 0) || // ALL pins - (pin >= 0 && _softpwm_channels[i].pin == pin)) // individual pin + for (uint8_t i = 0; i < SOFTPWM_MAXCHANNELS; i++) { + if (_softpwm_channels[i].pin == pin) { // set the pin (and exit, if individual pin) _softpwm_channels[i].pwmvalue = value; @@ -238,7 +201,7 @@ void SoftPWMSet(int8_t pin, uint8_t value, uint8_t hardset) { firstfree = i; } - if (pin >= 0 && firstfree >= 0) { + if (firstfree >= 0) { // we have a free pin we can use _softpwm_channels[firstfree].pin = pin; _softpwm_channels[firstfree].polarity = _softpwm_defaultPolarity; @@ -257,23 +220,34 @@ void SoftPWMSet(int8_t pin, uint8_t value, uint8_t hardset) { } } -void SoftPWMEnd(int8_t pin) { - uint8_t i; +void SoftPWMEnd(uint8_t pin) { - for (i = 0; i < SOFTPWM_MAXCHANNELS; i++) { - if ((pin < 0 && _softpwm_channels[i].pin >= 0) || // ALL pins - (pin >= 0 && _softpwm_channels[i].pin == pin)) // individual pin - { - // now disable the pin (put it into INPUT mode) + for (uint8_t i = 0; i < SOFTPWM_MAXCHANNELS; i++) { + if (_softpwm_channels[i].pin == pin) { + + // Disable pin output digitalWrite(_softpwm_channels[i].pin, 1); pinMode(_softpwm_channels[i].pin, INPUT); - // remove the pin + // Flag as removed _softpwm_channels[i].pin = -1; } } } +void SoftPWMEndAll() { + + for (uint8_t i = 0; i < SOFTPWM_MAXCHANNELS; i++) { + + // Disable pin output + digitalWrite(_softpwm_channels[i].pin, 1); + pinMode(_softpwm_channels[i].pin, INPUT); + + // Flag as removed + _softpwm_channels[i].pin = -1; + } +} + void SoftPWMSetFadeTime(int8_t pin, uint16_t fadeUpTime, uint16_t fadeDownTime) { int16_t fadeAmount; diff --git a/arduino/libraries/SoftPWM/SoftPWM.h b/arduino/libraries/SoftPWM/SoftPWM.h index 9a3da94..c754452 100644 --- a/arduino/libraries/SoftPWM/SoftPWM.h +++ b/arduino/libraries/SoftPWM/SoftPWM.h @@ -51,8 +51,6 @@ void SoftPWMBegin(uint8_t defaultPolarity = SOFTPWM_NORMAL); void SoftPWMSet(int8_t pin, uint8_t value, uint8_t hardset = 0); -void SoftPWMSetPercent(int8_t pin, uint8_t percent, uint8_t hardset = 0); - void SoftPWMEnd(int8_t pin); void SoftPWMSetFadeTime(int8_t pin, uint16_t fadeUpTime, uint16_t fadeDownTime); diff --git a/arduino/libraries/SoftPWM/changelog.txt b/arduino/libraries/SoftPWM/changelog.txt deleted file mode 100644 index 097ae1e..0000000 --- a/arduino/libraries/SoftPWM/changelog.txt +++ /dev/null @@ -1,13 +0,0 @@ -SoftPWM Library - -Version Modified By Date Comments -------- ------------ ---------- -------- -0001 B Hagman 2010-03-14 Initial coding (Pi Day!) -0002 B Hagman 2010-03-21 License updates, minor fixes -0003 B Hagman 2010-04-21 Added hardset control for syncing to matrix scan lines -0004 B Hagman 2010-06-27 Fixed: pin 0 could not be used. -0005 B Hagman 2011-05-27 Added polarity, and full Wiring support. - B Hagman 2012-02-13 Fixed Arduino 1.0+ mess. -1.0.0 B Hagman 2017-01-13 Initial release conforming to library standard. -1.0.1 P Stoffregen 2017-08-30 Use IntervalTimer on Teensy 3.x and use LED_BUILTIN for WLED - diff --git a/arduino/libraries/SoftPWM/examples/SoftPWM_Arduino_LED_Blink/SoftPWM_Arduino_LED_Blink.pde b/arduino/libraries/SoftPWM/examples/SoftPWM_Arduino_LED_Blink/SoftPWM_Arduino_LED_Blink.pde deleted file mode 100644 index e6e4ba6..0000000 --- a/arduino/libraries/SoftPWM/examples/SoftPWM_Arduino_LED_Blink/SoftPWM_Arduino_LED_Blink.pde +++ /dev/null @@ -1,18 +0,0 @@ -#include - -void setup() -{ - SoftPWMBegin(); - - SoftPWMSet(13, 0); - - SoftPWMSetFadeTime(13, 1000, 1000); -} - -void loop() -{ - SoftPWMSet(13, 255); - delay(1000); - SoftPWMSet(13, 0); - delay(1000); -} diff --git a/arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Bounce/SoftPWM_LEDHead_Bounce.pde b/arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Bounce/SoftPWM_LEDHead_Bounce.pde deleted file mode 100644 index ae0e0d0..0000000 --- a/arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Bounce/SoftPWM_LEDHead_Bounce.pde +++ /dev/null @@ -1,38 +0,0 @@ -#include - -#define DELAY 100 -uint8_t leds[8] = {22, 23, 26, 27, 28, 29, 30, 31}; - -void setup() -{ - SoftPWMBegin(); - - for (int i = 0; i < 8; i++) - SoftPWMSet(leds[i], 0); - - SoftPWMSetFadeTime(ALL, 50, 400); -} - -void loop() -{ - int i; - - for (i = 0; i < 7; i++) - { - SoftPWMSet(leds[i+1], 255); - SoftPWMSet(leds[i], 0); - delay(DELAY); - } - - delay(400); - - for (i = 7; i > 0; i--) - { - SoftPWMSet(leds[i-1], 255); - SoftPWMSet(leds[i], 0); - delay(DELAY); - } - - delay(400); - -} diff --git a/arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Bounce2/SoftPWM_LEDHead_Bounce2.pde b/arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Bounce2/SoftPWM_LEDHead_Bounce2.pde deleted file mode 100644 index b5d4f4e..0000000 --- a/arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Bounce2/SoftPWM_LEDHead_Bounce2.pde +++ /dev/null @@ -1,43 +0,0 @@ -#include - -#define DELAY 40 - -uint8_t leds[8] = {22, 23, 26, 27, 28, 29, 30, 31}; - -void setup() -{ - SoftPWMBegin(); - - for (int i = 0; i < 8; i++) - SoftPWMSet(leds[i], 0); - - SoftPWMSetFadeTime(ALL, 30, 200); - -} - -void loop() -{ - int i; - - for (i = 0; i < 3; i++) - { - SoftPWMSet(leds[i+1], 255); - SoftPWMSet(leds[6-i], 255); - SoftPWMSet(leds[i], 0); - SoftPWMSet(leds[7-i], 0); - delay(DELAY); - } - - delay(250); - - for (i = 3; i > 0; i--) - { - SoftPWMSet(leds[i-1], 255); - SoftPWMSet(leds[8-i], 255); - SoftPWMSet(leds[i], 0); - SoftPWMSet(leds[7-i], 0); - delay(DELAY); - } - - delay(250); -} diff --git a/arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Random_Blink/SoftPWM_LEDHead_Random_Blink.pde b/arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Random_Blink/SoftPWM_LEDHead_Random_Blink.pde deleted file mode 100644 index c2f84f0..0000000 --- a/arduino/libraries/SoftPWM/examples/SoftPWM_LEDHead_Random_Blink/SoftPWM_LEDHead_Random_Blink.pde +++ /dev/null @@ -1,24 +0,0 @@ -#include - -#define DELAY 100 -uint8_t leds[8] = {22, 23, 26, 27, 28, 29, 30, 31}; - -void setup() -{ - SoftPWMBegin(); - for (int i = 0; i < 8; i++) - SoftPWMSet(leds[i], 0); - - SoftPWMSetFadeTime(ALL, 50, 400); -} - -void loop() -{ - uint8_t pin = random(8); - - SoftPWMSet(leds[pin], 255); - delay(50); - SoftPWMSet(leds[pin], 0); - - delay(random(DELAY)); -} diff --git a/arduino/libraries/SoftPWM/examples/SoftPWM_Wiring_HeartBeat/SoftPWM_Wiring_HeartBeat.pde b/arduino/libraries/SoftPWM/examples/SoftPWM_Wiring_HeartBeat/SoftPWM_Wiring_HeartBeat.pde deleted file mode 100644 index b98bda6..0000000 --- a/arduino/libraries/SoftPWM/examples/SoftPWM_Wiring_HeartBeat/SoftPWM_Wiring_HeartBeat.pde +++ /dev/null @@ -1,30 +0,0 @@ -#include - -#ifndef WLED -#define WLED LED_BUILTIN -#endif - -void setup() -{ - SoftPWMBegin(); - - // Sets the PWM value to 0 for the built-in LED (WLED). - SoftPWMSet(WLED, 0); - - // Sets the default fade time for WLED to - // 100 ms fade-up and 550 ms to fade-down. - SoftPWMSetFadeTime(WLED, 100, 550); -} - -void loop() -{ - // Turn on WLED - SoftPWMSet(WLED, 255); - // Wait for the fade-up and some extra delay. - delay(250); - // Turn off WLED - SoftPWMSet(WLED, 0); - // Wait for the fade-down, and some extra delay. - delay(650); -} - diff --git a/arduino/libraries/SoftPWM/keywords.txt b/arduino/libraries/SoftPWM/keywords.txt deleted file mode 100644 index 9bc3cf2..0000000 --- a/arduino/libraries/SoftPWM/keywords.txt +++ /dev/null @@ -1,36 +0,0 @@ -######################################## -# Syntax Coloring Map For SoftPWM -######################################## -# -# Fields (Data Members) - KEYWORD2 -# Methods (Member Functions) -# - FUNCTION2 (or KEYWORD2) -# Constants - LITERAL2 -# Datatypes - KEYWORD5 (or KEYWORD1) -######################################## - -######################################## -# Datatypes (KEYWORD5 or KEYWORD1) -######################################## - -SoftPWM KEYWORD1 - -######################################## -# Methods and Functions -# (FUNCTION2 or KEYWORD2) -######################################## - -SoftPWMSet KEYWORD2 -SoftPWMSetPercent KEYWORD2 -SoftPWMSetFadeTime KEYWORD2 -SoftPWMBegin KEYWORD2 -SoftPWMEnd KEYWORD2 -SoftPWMSetPolarity KEYWORD2 - -######################################## -# Constants (LITERAL2) -######################################## - -ALL LITERAL2 -SOFTPWM_NORMAL LITERAL2 -SOFTPWM_INVERTED LITERAL2 diff --git a/arduino/libraries/SoftPWM/library.properties b/arduino/libraries/SoftPWM/library.properties deleted file mode 100644 index b1ab1f3..0000000 --- a/arduino/libraries/SoftPWM/library.properties +++ /dev/null @@ -1,9 +0,0 @@ -name=SoftPWM -version=1.0.1 -author=Brett Hagman -maintainer=Brett Hagman -sentence=A software library to produce a 50 percent duty cycle PWM signal on arbitrary pins.
-paragraph=A Wiring Framework (and Arduino) Library, for Atmel AVR8 bit series microcontrollers and Teensy 3.x, to produce PWM signals on any arbitrary pin.
It was originally designed for controlling the brightness of LEDs, but could be adapted to control servos and other low frequency PWM controlled devices as well.
It uses a single hardware timer (Timer 2) on an Atmel AVR 8 bit microcontroller (or IntervalTimer on Teensy 3.x) to generate up to 20 PWM channels (your mileage may vary).

Issues or questions: https://github.com/bhagman/SoftPWM/issues
-category=Signal Input/Output -url=https://github.com/bhagman/SoftPWM -architectures=avr,arm diff --git a/dozer_main.cpp b/dozer_main.cpp new file mode 100644 index 0000000..ebdfcd7 --- /dev/null +++ b/dozer_main.cpp @@ -0,0 +1,102 @@ +#include +#include +#include +#include +#include +#include +#include +#include "SoftPWM.h" + +#include +#include +#include + +#define CE_PIN 3 +#define CS_PIN 2 +#define RED 4 +#define GREEN 5 + +class Radio { + +public: + RF24 instance; + +}; + +class Motor { + +public: + int power; +}; + + +const uint64_t dozer_pipe = 0xF0F0F0F0D2LL; +const uint64_t remote_pipe = 0xF0F0F0F0E1LL; + +struct StickValues { + uint32_t stick_1_a; + uint32_t stick_1_b; + uint32_t stick_2_a; + uint32_t stick_2_b; +}; + +int main() { + + pinMode(4, OUTPUT); + pinMode(5, OUTPUT); + + uart_init(); + SoftPWMBegin(); + + RF24 radio(CE_PIN, CS_PIN); + radio.begin(); + radio.openWritingPipe(dozer_pipe); + radio.openReadingPipe(1, remote_pipe); + radio.startListening(); + + //digitalWrite(18, HIGH); + // SoftPWMSet(18, 255, 1); + + + digitalWrite(GREEN, HIGH); + _delay_ms(2000); + digitalWrite(GREEN, LOW); + + bool breaking = false; + int cycles = 0; + while (!breaking) { + + //unsigned long start_wait = micros(); + bool timeout = false; + + while (!radio.available()) { + if (cycles++ > 10) { + digitalWrite(RED, HIGH); + _delay_ms(50); + digitalWrite(RED, LOW); + _delay_ms(50); + timeout = true; + cycles = 0; + break; + } + + } + + if (timeout) { +// SoftPWMSet(17, 0); +// SoftPWMSet(18, 0); + } else { + + StickValues stick_values; + radio.read(&stick_values, sizeof(uint32_t)*4); + radio.flush_rx(); + radio.flush_tx(); + +// SoftPWMSet(17, stick_values.stick_1_a); +// SoftPWMSet(18, stick_values.stick_1_b); + } + + SoftPWMSet(17, 80); + SoftPWMSet(18, 120); + } +} diff --git a/main.cpp b/main.cpp deleted file mode 100644 index 515b624..0000000 --- a/main.cpp +++ /dev/null @@ -1,169 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "SoftPWM.h" - -#include -#include -#include - -#define CE_PIN 3 -#define CS_PIN 2 -#define RED 4 -#define GREEN 5 - -class Radio { - -public: - RF24 instance; - -}; - -class Motor { - -public: - int power; -}; - -const uint64_t pipes[2] = {0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL}; - -int radio_number = ROLE; -int role = ROLE; - -int main(void) { - - pinMode(4, OUTPUT); - pinMode(5, OUTPUT); - - uart_init(); - SoftPWMBegin(); - -// SoftPWMSetFadeTime(4, 2000, 2000); -// pinMode(15, OUTPUT); -// -// pinMode(16, OUTPUT); -// pinMode(17, OUTPUT); -// -// pinMode(18, OUTPUT); -// pinMode(19, OUTPUT); - - - RF24 radio(CE_PIN, CS_PIN); - radio.begin(); - - if (radio_number) { - radio.openWritingPipe(pipes[1]); - radio.openReadingPipe(1, pipes[0]); - } else { - radio.openWritingPipe(pipes[0]); - radio.openReadingPipe(1, pipes[1]); - } - - radio.startListening(); - - - SoftPWMSet(17, 255); - SoftPWMSet(18, 255); - - - //digitalWrite(18, HIGH); - // SoftPWMSet(18, 255, 1); -// digitalWrite(19, LOW); - -// digitalWrite(14, LOW); -// digitalWrite(15, HIGH); - - digitalWrite(GREEN, HIGH); - _delay_ms(200); - digitalWrite(GREEN, LOW); - - int accum = 20; - int i = 5; - for (;;) { - - unsigned long start_time = micros(); - - // ping - if (role == 1) { - - - if (accum > 230) { - i = -5; accum = 230; - } else if (accum < 100) { - i = 5; accum = 100; - } - accum += i; - - // SoftPWMSet(14, accum); - // SoftPWMSet(19, accum); - _delay_ms(100); -// -//// digitalWrite(GREEN, HIGH); -//// _delay_ms(200); -//// digitalWrite(GREEN, LOW); -// radio.stopListening(); -// -// -// if (!radio.write(&start_time, sizeof(unsigned long))) { -//// digitalWrite(RED, HIGH); -//// _delay_ms(1000); -//// digitalWrite(RED, LOW); -// radio.startListening(); -// continue; -// } -// -// radio.startListening(); -// unsigned long started_waiting_at = micros(); -// boolean timeout = false; -// -// _delay_ms(390); -// if (!radio.available()) { -// timeout = true; -// } -//// while (!radio.available()) { -//// if (micros() - started_waiting_at > 20) { -//// timeout = true; -//// break; -//// } -//// } -// if (timeout) { -// -//// digitalWrite(RED, HIGH); -//// _delay_ms(200); -//// digitalWrite(RED, LOW); -// -// } else { -// unsigned long got_time; -// radio.read(&got_time, sizeof(unsigned long)); -// unsigned long end_time = micros(); -// -//// digitalWrite(GREEN, HIGH); -//// _delay_ms(200); -//// digitalWrite(GREEN, LOW); -// } - - - //_delay_ms(500); - - } - - // ping bag - if (role == 0) { - _delay_ms(100); - unsigned long got_time; - if (radio.available()) { - while (radio.available()) { - radio.read(&got_time, sizeof(unsigned long)); - } - radio.stopListening(); - radio.write(&got_time, sizeof(unsigned long)); - radio.startListening(); - } - } - } -} - diff --git a/remote_main.cpp b/remote_main.cpp new file mode 100644 index 0000000..328c9d1 --- /dev/null +++ b/remote_main.cpp @@ -0,0 +1,81 @@ +#include +#include +#include +#include +#include +#include +#include +#include "SoftPWM.h" + +#include +#include +#include + +#define CE_PIN 3 +#define CS_PIN 2 +#define RED 4 +#define GREEN 5 + +class Radio { + +public: + RF24 instance; + +}; + +class Motor { + +public: + int power; +}; + +const uint64_t dozer_pipe = 0xF0F0F0F0D2LL; +const uint64_t remote_pipe = 0xF0F0F0F0E1LL; + +struct StickValues { + uint32_t stick_1_a; + uint32_t stick_1_b; + uint32_t stick_2_a; + uint32_t stick_2_b; +}; + +int main() { + + pinMode(4, OUTPUT); + pinMode(5, OUTPUT); + + uart_init(); + + RF24 radio(CE_PIN, CS_PIN); + radio.begin(); + radio.openWritingPipe(remote_pipe); + radio.openReadingPipe(1, dozer_pipe); + radio.startListening(); + + bool breaking = false; + while (!breaking) { + + _delay_ms(100); + + // Get input + + // Parse into a struct + StickValues stick_values; + stick_values.stick_1_a = 100; + stick_values.stick_1_b = 50; + stick_values.stick_2_a = 0; + stick_values.stick_2_b = 0; + + // Send to dozer + radio.stopListening(); + radio.write(&stick_values, sizeof(uint32_t)*4); + radio.startListening(); + } +} + +// Dot really ever have to read +//if (radio.available()) { +// while (radio.available()) { +// radio.read(&got_time, sizeof(unsigned long)); +// } +//} \ No newline at end of file