Show Posts
|
|
Pages: [1]
|
|
1
|
Using Arduino / Programming Questions / Re: Understanding counting with arrays
|
on: September 21, 2012, 01:30:16 pm
|
I'm not sure why you're accusing me of stealing; that's quite out of line. Would you have preferred borrowed, acquired, got permission to use? My point was NOT to accuse you of having acquired the code inappropriately. I'm sorry that it came across that way. You did, however, take the code as yours to do with as you see fit. No one has a problem with you doing that. That's why code is published in the first place. Where I did have a problem was with the attitude that "I didn't develop this code, so I have no responsibility to understand it". At least that was the impression I got. no hard feelings. we're all here to learn something, right? but if i may, the tone of my responses is quite the opposite: "i didn't develop this code, but i want to use it. can someone help me understand it?" it's a simple question, but even with all the responses, it hasn't been touched on in the slightest...
|
|
|
|
|
3
|
Using Arduino / Programming Questions / Re: Understanding counting with arrays
|
on: September 20, 2012, 09:31:30 pm
|
when i shrank the project down, i had to get rid of the pot But you couldn't delete the comment? i'm sorry. this code isn't mine You stole it. You modified it. It IS now yours. You are saying that since you didn't invent it, you don't have any requirement to understand it, to improve it, or to debug it. That attitude is not acceptable around here. excuse me? you're right. as i stated in my original post, i am new to this. i posted a comment on the original authors blog and he pointed me here. i came here hoping for help with my code, not to be instigated by you. if you read the title of my post, it starts with the word "Understanding," so at this point you are just putting words in my mouth. I'm not sure why you're accusing me of stealing; that's quite out of line. It clearly states that it is free for modification at the beginning of the sketch. Since I modified it for my purposes, then yes, I agree this version is now mine. If anything, it seems YOU are the one with the attitude, bud. if there is anyone else willing to help me understand my code in a constructive way, i would greatly appreciate it.
|
|
|
|
|
5
|
Using Arduino / Programming Questions / Understanding counting with arrays
|
on: September 17, 2012, 08:44:43 pm
|
Hello all, I got my first UNO a few weeks ago and have been managing my way thru various projects here and there. One of which was to incorporate some LEDs into some toy helicopters for flying at night -- big thanks to mr. klein! Here's a video of how things turned out: http://youtu.be/mlnc5H0nKGgI built a socket into the project to allow for adding more patterns later and this is where i'm running into some trouble: if i add too many entries to my array, the program fails to operate correctly. Here's another vid to further illustrate the problem: http://youtu.be/tYSITXTB9sUThe first 25 seconds show normal operation while the latter part of the video shows what happens after uncommenting the line in the brightness_pattern array. It doesn't matter which line is commented out in the array, 7 entries is okay but 8 is too many. FWIW, I originally wrote the program with an UNO board but then trimmed it down for use on an ATTiny44 at 8MHz The code: // // www.blinkenlight.net // // Copyright 2011 Udo Klein // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see http://www.gnu.org/licenses/
#include <EEPROM.h>
uint8_t get_next_count(const uint8_t count_limit) { // n cells to use --> 1/n wear per cll --> n times the life time const uint16_t cells_to_use = 256;
// default cell to change uint8_t change_this_cell = 0; // value of the default cell uint8_t change_value = EEPROM.read(change_this_cell);
// will be used to aggregate the count_limit // must be able to hold values up to cells_to_use*255 + 1 uint32_t count = change_value;
for (uint16_t cell = 1; cell < cells_to_use; ++cell) { uint8_t value = EEPROM.read(cell);
// determine current count by cummulating all cells count += value;
if (value != change_value ) { // at the same time find at least one cell that differs change_this_cell = cell; } }
// Either a cell differs from cell 0 --> change it // Otherwise no cell differs from cell 0 --> change cell 0
// Since a cell might initially hold a value of -1 the % operator must be applied twice EEPROM.write(change_this_cell, (EEPROM.read(change_this_cell) % count_limit + 1) % count_limit);
// return the new count return (count + 1) % count_limit; }
uint8_t brightness_pattern_1(const int8_t led, const int8_t pos) { switch (abs(led-pos+2)) { case 0: return 40; case 1: return 20; case 2: return 10; case 3: return 1; default: return 1; //brightness } }
uint8_t brightness_pattern_2(const int8_t led, const int8_t pos) { switch (abs(led-pos+2)) { case 0: return 40; case 1: return 20; case 2: return 1; case 3: return 0; default: return 0; //brightness } }
uint8_t brightness_pattern_3(const int8_t led, const int8_t pos) { switch min(abs(led-pos-1),abs(10-led-pos-1)) { case 0: return 40; case 1: return 20; case 2: return 10; case 3: return 1; default: return 1; //brightness } }
uint8_t brightness_pattern_4(const int8_t led, const int8_t pos) { switch min(abs(led-pos-1),abs(10-led-pos-1)) { case 0: return 40; case 1: return 20; case 2: return 1; case 3: return 0; default: return 0; //brightness } }
uint8_t brightness_pattern_5(const int8_t led, const int8_t pos) { int8_t tmp = 2*pos - abs(2*led-10)-2; //last number is middle delay return (tmp>0? tmp+tmp>>1: 1); //brightness }
uint8_t brightness_pattern_6(const int8_t led, const int8_t pos) { int8_t tmp = 2*pos - abs(2*led-10)-2; //last number is middle delay return (tmp>0? tmp+tmp>>1: 0); //brightness }
uint8_t brightness_pattern_7(const int8_t led, const int8_t pos) { // inverse of brightness_pattern_8 int8_t tmp = abs(2*led-10) + 8 - pos; // abs(2*led-[#LEDs - 1]) + delay in middle - pos - delay at outside return (tmp>0? tmp+tmp>>1: 0); //brightness }
uint8_t brightness_pattern_8(const int8_t led, const int8_t pos) { // inverse of brightness_pattern_7 int8_t tmp = abs(2*led-10) + 25 - 2*pos; // abs(2*led-[#LEDs - 1]) + delay in middle - pos - delay at outside return (tmp>0? tmp+tmp>>1: 0); //brightness }
typedef uint8_t (*brightness_pattern)(const int8_t, const int8_t);
brightness_pattern pattern[] = { brightness_pattern_1, brightness_pattern_2, // brightness_pattern_3, *************the problem seems to be here in this array************* brightness_pattern_4, brightness_pattern_5, brightness_pattern_6, brightness_pattern_7, brightness_pattern_8, };
brightness_pattern brightness;
void setup() { for (uint8_t pin=0; pin<11; ++pin) { pinMode(pin, OUTPUT); }
brightness = pattern[get_next_count(sizeof(pattern)/sizeof(pattern[0]))]; }
void pulse_width_modulation(const uint8_t pos) { for(uint8_t times=0; times<8; ++times) { for (uint8_t pass=0; pass<40; ++pass) { //brightness on or off...overall brightness (flicker) for (int8_t led=-3; led<11; ++led) { digitalWrite(led, (brightness(led, pos) > pass)); } } } }
void loop() { // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: //delay(2); static uint8_t pos=0;
while(pos<16) { pulse_width_modulation(pos); ++pos; }
while(pos>0) { --pos; pulse_width_modulation(pos); } }
thanks!
|
|
|
|
|
7
|
Using Arduino / Microcontrollers / Re: How to program ATtiny45 with Arduino Leonardo as ISP
|
on: September 17, 2012, 08:08:39 pm
|
|
thanks for the wonderful write up, peter!
i've seen all that information scattered across multiple threads, but this is the first time its been put together in a coherent manner
i'm eager to see if this will finally fix my woes...i couldn't wait and bought an UNO a few weeks ago but haven't lost hope for my leo
|
|
|
|
|
9
|
Using Arduino / Microcontrollers / Re: Having trouble with new ATMega328
|
on: August 24, 2012, 04:00:31 am
|
Riva- i tried loadin this sketch: Atmega_Board_Programmer.ino but i still get the same error: avrdude: stk500_getsync(): not in sync: resp=0x00 And the serial minitor doesnt say anything...
i am having the exact same problem. i've tried it with both with factory attiny85s and an arduino-bootloaded atmega328 but no luck either
|
|
|
|
|
10
|
Using Arduino / Microcontrollers / Re: UNO R3 ISP trouble (ATtiny45)
|
on: August 22, 2012, 03:32:01 am
|
I am pleased to announce that it worked!!! I'll be making an Intsructable teaching other people how to load .hex files onto the ATtiny45 using the Arduino as an ISP. Hopefully I can save someone else the headache. Thanks again for all your help!!
oh man this would very much be appreciated 
|
|
|
|
|
12
|
Using Arduino / Microcontrollers / Avrdude error with Leonardo ISP
|
on: August 18, 2012, 08:49:56 am
|
Hello all, I am fairly new to all of this and I'm still trying to get my bearings, but I've exhausted every outlet that I have come across--to no avail. I bought the Olimexino 32U4 Leonard-like board ( https://www.olimex.com/dev/olimexino-32u4.html) and I've been trying to use it as a ISP to bootload/program a couple of Attiny85s but I keep getting the dreaded out of sync error whenever i try to burn the bootloader/upload a sketch. I've updated to the latest Tiny cores as well as the modified ArduinoISP.ino sketch but the error remains. avrdude: Version 5.11, compiled on Sep 2 2011 at 19:38:36 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ Copyright (c) 2007-2009 Joerg Wunsch
System wide configuration file is "C:\arduino-1.0.1-windows\arduino-1.0.1\hardware/tools/avr/etc/avrdude.conf"
Using Port : \\.\COM8 Using Programmer : stk500v1 Overriding Baud Rate : 19200 avrdude: Send: 0 [30] [20] avrdude: Send: 0 [30] [20] avrdude: Send: 0 [30] [20] avrdude: Recv: avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude done. Thank you.
In addition, I've been unable to get any output on my serial monitor when using this sketch: http://www.gammon.com.au/forum/?id=11633I've checked and rechecked my pins--MISO, MOSI, SCK all come from the dedicated pins and RESET is connected to D10 while 5V and GND are attached to the rails. When I load the sketch, an LED i attached to the MOSI pin lights up but then I'm stuck after that. I appreciate any help. I wish I'd gotten my first Arduino earlier 
|
|
|
|
|