Arduino code Noob Need help

Discussion in 'The Projects Forum' started by Turkish, Sep 2, 2010.

  1. Turkish

    Thread Starter New Member

    May 16, 2010
    24
    0
    I used the code in this link http://www.instructables.com/files/orig/F9G/B4OS/G8AS45XZ/F9GB4OSG8AS45XZ.tmp and modified it to control pins 0-21 (not using pin 13) on my arduino mega for my led table now i have 2 sets of 16 led's that need to be controled separatly by potentiometers. I'm trying to get the led's to light up sequentialy and have the speed increase as the resistance is changed with the potentiometer. But I'm failing at that and I'm failing even more at merging the codes together to work at the same time.

    So basically I need pins 0-21 excluding 13 to be my VU meter and pins 22-37 to be potentiometer controlled sequential leds and pins 38-53 to be potentiometer controlled sequential leds.

    Could someone please help me, I'm kinda in a bind I need to get it done for my party this weekend.
     
  2. Bosparra

    Member

    Feb 17, 2010
    79
    3
    Provide a link to the download page and not the actual download. I'll see if I can assist.
     
  3. Turkish

    Thread Starter New Member

    May 16, 2010
    24
    0
    Code ( (Unknown Language)):
    1. // these constants describe the pins. They won't change:
    2. const int soundpin = 8; //reads the power from the light sensor
    3. const int LED1= 0; //LED's 1-6 numbered accordingly
    4. const int LED2= 1;
    5. const int LED3= 2;
    6. const int LED4= 3;
    7. const int LED5= 4;
    8. const int LED6= 5; //LED's 1-6 numbered accordingly
    9. const int LED7= 6;
    10. const int LED8= 7;
    11. const int LED9= 8;
    12. const int LED10= 9;
    13. const int LED11= 10; //LED's 1-6 numbered accordingly
    14. const int LED12= 11;
    15. const int LED13= 12;
    16. const int LED14= 21;
    17. const int LED15= 14;
    18. const int LED16= 15; //LED's 1-6 numbered accordingly
    19. const int LED17= 16;
    20. const int LED18= 17;
    21. const int LED19= 18;
    22. const int LED20= 19;
    23. const int LED21= 20;
    24. int sound[4];
    25. int soundav;
    26.  
    27. void setup()
    28. {
    29. // initialize the serial communications:
    30. Serial.begin(9600);
    31.  
    32. // Provide ground and power by using the analog inputs as normal
    33. // digital pins. This makes it possible to directly connect the
    34. // breakout board to the Arduino. If you use the normal 5V and
    35. // GND pins on the Arduino, you can remove these lines.
    36. pinMode(soundpin, INPUT);
    37. pinMode(LED1, OUTPUT);
    38. pinMode(LED2, OUTPUT);
    39. pinMode(LED3, OUTPUT);
    40. pinMode(LED4, OUTPUT);
    41. pinMode(LED5, OUTPUT);
    42. pinMode(LED6, OUTPUT);
    43. pinMode(LED7, OUTPUT);
    44. pinMode(LED8, OUTPUT);
    45. pinMode(LED9, OUTPUT);
    46. pinMode(LED10, OUTPUT);
    47. pinMode(LED11, OUTPUT);
    48. pinMode(LED12, OUTPUT);
    49. pinMode(LED13, OUTPUT);
    50. pinMode(LED14, OUTPUT);
    51. pinMode(LED15, OUTPUT);
    52. pinMode(LED16, OUTPUT);
    53. pinMode(LED17, OUTPUT);
    54. pinMode(LED18, OUTPUT);
    55. pinMode(LED19, OUTPUT);
    56. pinMode(LED20, OUTPUT);
    57. pinMode(LED21, OUTPUT);
    58. }
    59. void loop()
    60. {
    61. for(int num=0;num<4;num++)
    62. {
    63. sound[num]=analogRead(soundpin);
    64. if(num==2)
    65. {
    66. soundav=(sound[0]+sound[1]+sound[2]+sound[3])/4;
    67. if((soundav)>210)
    68. {
    69. digitalWrite(LED1,HIGH);
    70. digitalWrite(LED2, HIGH); // set the LED on
    71. digitalWrite(LED3,HIGH);
    72. digitalWrite(LED4, HIGH); // set the LED on
    73. digitalWrite(LED5,HIGH);
    74. digitalWrite(LED6,HIGH);
    75. digitalWrite(LED7, HIGH); // set the LED on
    76. digitalWrite(LED8,HIGH);
    77. digitalWrite(LED9, HIGH); // set the LED on
    78. digitalWrite(LED10,HIGH);
    79. digitalWrite(LED11,HIGH);
    80. digitalWrite(LED12, HIGH); // set the LED on
    81. digitalWrite(LED13,HIGH);
    82. digitalWrite(LED14, HIGH); // set the LED on
    83. digitalWrite(LED15,HIGH);
    84. digitalWrite(LED16,HIGH);
    85. digitalWrite(LED17, HIGH); // set the LED on
    86. digitalWrite(LED18,HIGH);
    87. digitalWrite(LED19, HIGH); // set the LED on
    88. digitalWrite(LED20,HIGH);
    89. digitalWrite(LED21,HIGH);
    90. }
    91. else if((soundav)>200)
    92. {
    93. digitalWrite(LED1,HIGH);
    94. digitalWrite(LED2, HIGH); // set the LED on
    95. digitalWrite(LED3,HIGH);
    96. digitalWrite(LED4, HIGH); // set the LED on
    97. digitalWrite(LED5,HIGH);
    98. digitalWrite(LED6,HIGH);
    99. digitalWrite(LED7, HIGH); // set the LED on
    100. digitalWrite(LED8,HIGH);
    101. digitalWrite(LED9, HIGH); // set the LED on
    102. digitalWrite(LED10,HIGH);
    103. digitalWrite(LED11,HIGH);
    104. digitalWrite(LED12, HIGH); // set the LED on
    105. digitalWrite(LED13,HIGH);
    106. digitalWrite(LED14, HIGH); // set the LED on
    107. digitalWrite(LED15,HIGH);
    108. digitalWrite(LED16,HIGH);
    109. digitalWrite(LED17, HIGH); // set the LED on
    110. digitalWrite(LED18,HIGH);
    111. digitalWrite(LED19, HIGH); // set the LED on
    112. digitalWrite(LED20,HIGH);
    113. digitalWrite(LED21,LOW);
    114. }
    115. else if((soundav)>190)
    116. {
    117. digitalWrite(LED1,HIGH);
    118. digitalWrite(LED2, HIGH); // set the LED on
    119. digitalWrite(LED3,HIGH);
    120. digitalWrite(LED4, HIGH); // set the LED on
    121. digitalWrite(LED5,HIGH);
    122. digitalWrite(LED6,HIGH);
    123. digitalWrite(LED7, HIGH); // set the LED on
    124. digitalWrite(LED8,HIGH);
    125. digitalWrite(LED9, HIGH); // set the LED on
    126. digitalWrite(LED10,HIGH);
    127. digitalWrite(LED11,HIGH);
    128. digitalWrite(LED12, HIGH); // set the LED on
    129. digitalWrite(LED13,HIGH);
    130. digitalWrite(LED14, HIGH); // set the LED on
    131. digitalWrite(LED15,HIGH);
    132. digitalWrite(LED16,HIGH);
    133. digitalWrite(LED17, HIGH); // set the LED on
    134. digitalWrite(LED18,HIGH);
    135. digitalWrite(LED19, HIGH); // set the LED on
    136. digitalWrite(LED20,LOW);
    137. digitalWrite(LED21,LOW);
    138. }
    139. else if(soundav>180)
    140. {
    141. digitalWrite(LED1,HIGH);
    142. digitalWrite(LED2, HIGH); // set the LED on
    143. digitalWrite(LED3,HIGH);
    144. digitalWrite(LED4, HIGH); // set the LED on
    145. digitalWrite(LED5,HIGH);
    146. digitalWrite(LED6,HIGH);
    147. digitalWrite(LED7, HIGH); // set the LED on
    148. digitalWrite(LED8,HIGH);
    149. digitalWrite(LED9, HIGH); // set the LED on
    150. digitalWrite(LED10,HIGH);
    151. digitalWrite(LED11,HIGH);
    152. digitalWrite(LED12, HIGH); // set the LED on
    153. digitalWrite(LED13,HIGH);
    154. digitalWrite(LED14, HIGH); // set the LED on
    155. digitalWrite(LED15,HIGH);
    156. digitalWrite(LED16,HIGH);
    157. digitalWrite(LED17, HIGH); // set the LED on
    158. digitalWrite(LED18,HIGH);
    159. digitalWrite(LED19, LOW); // set the LED on
    160. digitalWrite(LED20,LOW);
    161. digitalWrite(LED21,LOW);
    162. }
    163. else if(soundav>170)
    164. {
    165. digitalWrite(LED1,HIGH);
    166. digitalWrite(LED2, HIGH); // set the LED on
    167. digitalWrite(LED3,HIGH);
    168. digitalWrite(LED4, HIGH); // set the LED on
    169. digitalWrite(LED5,HIGH);
    170. digitalWrite(LED6,HIGH);
    171. digitalWrite(LED7, HIGH); // set the LED on
    172. digitalWrite(LED8,HIGH);
    173. digitalWrite(LED9, HIGH); // set the LED on
    174. digitalWrite(LED10,HIGH);
    175. digitalWrite(LED11,HIGH);
    176. digitalWrite(LED12, HIGH); // set the LED on
    177. digitalWrite(LED13,HIGH);
    178. digitalWrite(LED14, HIGH); // set the LED on
    179. digitalWrite(LED15,HIGH);
    180. digitalWrite(LED16,HIGH);
    181. digitalWrite(LED17, HIGH); // set the LED on
    182. digitalWrite(LED18,LOW);
    183. digitalWrite(LED19, LOW); // set the LED on
    184. digitalWrite(LED20,LOW);
    185. digitalWrite(LED21,LOW);
    186. }
    187. else if(soundav>160)
    188. {
    189. digitalWrite(LED1,HIGH);
    190. digitalWrite(LED2, HIGH); // set the LED on
    191. digitalWrite(LED3,HIGH);
    192. digitalWrite(LED4, HIGH); // set the LED on
    193. digitalWrite(LED5,HIGH);
    194. digitalWrite(LED6,HIGH);
    195. digitalWrite(LED7, HIGH); // set the LED on
    196. digitalWrite(LED8,HIGH);
    197. digitalWrite(LED9, HIGH); // set the LED on
    198. digitalWrite(LED10,HIGH);
    199. digitalWrite(LED11,HIGH);
    200. digitalWrite(LED12, HIGH); // set the LED on
    201. digitalWrite(LED13,HIGH);
    202. digitalWrite(LED14, HIGH); // set the LED on
    203. digitalWrite(LED15,HIGH);
    204. digitalWrite(LED16,HIGH);
    205. digitalWrite(LED17, LOW); // set the LED on
    206. digitalWrite(LED18,LOW);
    207. digitalWrite(LED19, LOW); // set the LED on
    208. digitalWrite(LED20,LOW);
    209. digitalWrite(LED21,LOW);
    210. }
    211. else if(soundav>150)
    212. {
    213. digitalWrite(LED1,HIGH);
    214. digitalWrite(LED2, HIGH); // set the LED on
    215. digitalWrite(LED3,HIGH);
    216. digitalWrite(LED4, HIGH); // set the LED on
    217. digitalWrite(LED5,HIGH);
    218. digitalWrite(LED6,HIGH);
    219. digitalWrite(LED7, HIGH); // set the LED on
    220. digitalWrite(LED8,HIGH);
    221. digitalWrite(LED9, HIGH); // set the LED on
    222. digitalWrite(LED10,HIGH);
    223. digitalWrite(LED11,HIGH);
    224. digitalWrite(LED12, HIGH); // set the LED on
    225. digitalWrite(LED13,HIGH);
    226. digitalWrite(LED14, HIGH); // set the LED on
    227. digitalWrite(LED15,HIGH);
    228. digitalWrite(LED16,LOW);
    229. digitalWrite(LED17, LOW); // set the LED on
    230. digitalWrite(LED18,LOW);
    231. digitalWrite(LED19, LOW); // set the LED on
    232. digitalWrite(LED20,LOW);
    233. digitalWrite(LED21,LOW);
    234. }
    235. else if(soundav>140)
    236. {
    237. digitalWrite(LED1,HIGH);
    238. digitalWrite(LED2, HIGH); // set the LED on
    239. digitalWrite(LED3,HIGH);
    240. digitalWrite(LED4, HIGH); // set the LED on
    241. digitalWrite(LED5,HIGH);
    242. digitalWrite(LED6,HIGH);
    243. digitalWrite(LED7, HIGH); // set the LED on
    244. digitalWrite(LED8,HIGH);
    245. digitalWrite(LED9, HIGH); // set the LED on
    246. digitalWrite(LED10,HIGH);
    247. digitalWrite(LED11,HIGH);
    248. digitalWrite(LED12, HIGH); // set the LED on
    249. digitalWrite(LED13,HIGH);
    250. digitalWrite(LED14, HIGH); // set the LED on
    251. digitalWrite(LED15,LOW);
    252. digitalWrite(LED16,LOW);
    253. digitalWrite(LED17, LOW); // set the LED on
    254. digitalWrite(LED18,LOW);
    255. digitalWrite(LED19, LOW); // set the LED on
    256. digitalWrite(LED20,LOW);
    257. digitalWrite(LED21,LOW);
    258. }
    259. else if(soundav>130)
    260. {
    261. digitalWrite(LED1,HIGH);
    262. digitalWrite(LED2, HIGH); // set the LED on
    263. digitalWrite(LED3,HIGH);
    264. digitalWrite(LED4, HIGH); // set the LED on
    265. digitalWrite(LED5,HIGH);
    266. digitalWrite(LED6,HIGH);
    267. digitalWrite(LED7, HIGH); // set the LED on
    268. digitalWrite(LED8,HIGH);
    269. digitalWrite(LED9, HIGH); // set the LED on
    270. digitalWrite(LED10,HIGH);
    271. digitalWrite(LED11,HIGH);
    272. digitalWrite(LED12, HIGH); // set the LED on
    273. digitalWrite(LED13,HIGH);
    274. digitalWrite(LED14, LOW); // set the LED on
    275. digitalWrite(LED15,LOW);
    276. digitalWrite(LED16,LOW);
    277. digitalWrite(LED17, LOW); // set the LED on
    278. digitalWrite(LED18,LOW);
    279. digitalWrite(LED19, LOW); // set the LED on
    280. digitalWrite(LED20,LOW);
    281. digitalWrite(LED21,LOW);
    282. }
    283. else if(soundav>120)
    284. {
    285. digitalWrite(LED1,HIGH);
    286. digitalWrite(LED2, HIGH); // set the LED on
    287. digitalWrite(LED3,HIGH);
    288. digitalWrite(LED4, HIGH); // set the LED on
    289. digitalWrite(LED5,HIGH);
    290. digitalWrite(LED6,HIGH);
    291. digitalWrite(LED7, HIGH); // set the LED on
    292. digitalWrite(LED8,HIGH);
    293. digitalWrite(LED9, HIGH); // set the LED on
    294. digitalWrite(LED10,HIGH);
    295. digitalWrite(LED11,HIGH);
    296. digitalWrite(LED12, HIGH); // set the LED on
    297. digitalWrite(LED13,LOW);
    298. digitalWrite(LED14, LOW); // set the LED on
    299. digitalWrite(LED15,LOW);
    300. digitalWrite(LED16,LOW);
    301. digitalWrite(LED17, LOW); // set the LED on
    302. digitalWrite(LED18,LOW);
    303. digitalWrite(LED19, LOW); // set the LED on
    304. digitalWrite(LED20,LOW);
    305. digitalWrite(LED21,LOW);
    306. }
     
  4. Turkish

    Thread Starter New Member

    May 16, 2010
    24
    0
    Code ( (Unknown Language)):
    1. else if(soundav>110)
    2. {
    3. digitalWrite(LED1,HIGH);
    4. digitalWrite(LED2, HIGH); // set the LED on
    5. digitalWrite(LED3,HIGH);
    6. digitalWrite(LED4, HIGH); // set the LED on
    7. digitalWrite(LED5,HIGH);
    8. digitalWrite(LED6,HIGH);
    9. digitalWrite(LED7, HIGH); // set the LED on
    10. digitalWrite(LED8,HIGH);
    11. digitalWrite(LED9, HIGH); // set the LED on
    12. digitalWrite(LED10,HIGH);
    13. digitalWrite(LED11,HIGH);
    14. digitalWrite(LED12, LOW); // set the LED on
    15. digitalWrite(LED13,LOW);
    16. digitalWrite(LED14, LOW); // set the LED on
    17. digitalWrite(LED15,LOW);
    18. digitalWrite(LED16,LOW);
    19. digitalWrite(LED17, LOW); // set the LED on
    20. digitalWrite(LED18,LOW);
    21. digitalWrite(LED19, LOW); // set the LED on
    22. digitalWrite(LED20,LOW);
    23. digitalWrite(LED21,LOW);
    24. }
    25. else if(soundav>100)
    26. {
    27. digitalWrite(LED1,HIGH);
    28. digitalWrite(LED2, HIGH); // set the LED on
    29. digitalWrite(LED3,HIGH);
    30. digitalWrite(LED4, HIGH); // set the LED on
    31. digitalWrite(LED5,HIGH);
    32. digitalWrite(LED6,HIGH);
    33. digitalWrite(LED7, HIGH); // set the LED on
    34. digitalWrite(LED8,HIGH);
    35. digitalWrite(LED9, HIGH); // set the LED on
    36. digitalWrite(LED10,HIGH);
    37. digitalWrite(LED11,LOW);
    38. digitalWrite(LED12, LOW); // set the LED on
    39. digitalWrite(LED13,LOW);
    40. digitalWrite(LED14, LOW); // set the LED on
    41. digitalWrite(LED15,LOW);
    42. digitalWrite(LED16,LOW);
    43. digitalWrite(LED17, LOW); // set the LED on
    44. digitalWrite(LED18,LOW);
    45. digitalWrite(LED19, LOW); // set the LED on
    46. digitalWrite(LED20,LOW);
    47. digitalWrite(LED21,LOW);
    48. }
    49. else if(soundav>90)
    50. {
    51. digitalWrite(LED1,HIGH);
    52. digitalWrite(LED2, HIGH); // set the LED on
    53. digitalWrite(LED3,HIGH);
    54. digitalWrite(LED4, HIGH); // set the LED on
    55. digitalWrite(LED5,HIGH);
    56. digitalWrite(LED6,HIGH);
    57. digitalWrite(LED7, HIGH); // set the LED on
    58. digitalWrite(LED8,HIGH);
    59. digitalWrite(LED9, HIGH); // set the LED on
    60. digitalWrite(LED10,LOW);
    61. digitalWrite(LED11,LOW);
    62. digitalWrite(LED12, LOW); // set the LED on
    63. digitalWrite(LED13,LOW);
    64. digitalWrite(LED14, LOW); // set the LED on
    65. digitalWrite(LED15,LOW);
    66. digitalWrite(LED16,LOW);
    67. digitalWrite(LED17, LOW); // set the LED on
    68. digitalWrite(LED18,LOW);
    69. digitalWrite(LED19, LOW); // set the LED on
    70. digitalWrite(LED20,LOW);
    71. digitalWrite(LED21,LOW);
    72. }
    73. else if(soundav>80)
    74. {
    75. digitalWrite(LED1,HIGH);
    76. digitalWrite(LED2, HIGH); // set the LED on
    77. digitalWrite(LED3,HIGH);
    78. digitalWrite(LED4, HIGH); // set the LED on
    79. digitalWrite(LED5,HIGH);
    80. digitalWrite(LED6,HIGH);
    81. digitalWrite(LED7, HIGH); // set the LED on
    82. digitalWrite(LED8,HIGH);
    83. digitalWrite(LED9, LOW); // set the LED on
    84. digitalWrite(LED10,LOW);
    85. digitalWrite(LED11,LOW);
    86. digitalWrite(LED12, LOW); // set the LED on
    87. digitalWrite(LED13,LOW);
    88. digitalWrite(LED14, LOW); // set the LED on
    89. digitalWrite(LED15,LOW);
    90. digitalWrite(LED16,LOW);
    91. digitalWrite(LED17, LOW); // set the LED on
    92. digitalWrite(LED18,LOW);
    93. digitalWrite(LED19, LOW); // set the LED on
    94. digitalWrite(LED20,LOW);
    95. digitalWrite(LED21,LOW);
    96. }
    97. else if(soundav>70)
    98. {
    99. digitalWrite(LED1,HIGH);
    100. digitalWrite(LED2, HIGH); // set the LED on
    101. digitalWrite(LED3,HIGH);
    102. digitalWrite(LED4, HIGH); // set the LED on
    103. digitalWrite(LED5,HIGH);
    104. digitalWrite(LED6,HIGH);
    105. digitalWrite(LED7, HIGH); // set the LED on
    106. digitalWrite(LED8,LOW);
    107. digitalWrite(LED9, LOW); // set the LED on
    108. digitalWrite(LED10,LOW);
    109. digitalWrite(LED11,LOW);
    110. digitalWrite(LED12, LOW); // set the LED on
    111. digitalWrite(LED13,LOW);
    112. digitalWrite(LED14, LOW); // set the LED on
    113. digitalWrite(LED15,LOW);
    114. digitalWrite(LED16,LOW);
    115. digitalWrite(LED17, LOW); // set the LED on
    116. digitalWrite(LED18,LOW);
    117. digitalWrite(LED19, LOW); // set the LED on
    118. digitalWrite(LED20,LOW);
    119. digitalWrite(LED21,LOW);
    120. }
    121. else if(soundav>60)
    122. {
    123. digitalWrite(LED1,HIGH);
    124. digitalWrite(LED2, HIGH); // set the LED on
    125. digitalWrite(LED3,HIGH);
    126. digitalWrite(LED4, HIGH); // set the LED on
    127. digitalWrite(LED5,HIGH);
    128. digitalWrite(LED6,HIGH);
    129. digitalWrite(LED7, LOW); // set the LED on
    130. digitalWrite(LED8,LOW);
    131. digitalWrite(LED9, LOW); // set the LED on
    132. digitalWrite(LED10,LOW);
    133. digitalWrite(LED11,LOW);
    134. digitalWrite(LED12, LOW); // set the LED on
    135. digitalWrite(LED13,LOW);
    136. digitalWrite(LED14, LOW); // set the LED on
    137. digitalWrite(LED15,LOW);
    138. digitalWrite(LED16,LOW);
    139. digitalWrite(LED17, LOW); // set the LED on
    140. digitalWrite(LED18,LOW);
    141. digitalWrite(LED19, LOW); // set the LED on
    142. digitalWrite(LED20,LOW);
    143. digitalWrite(LED21,LOW);
    144. }
    145. else if(soundav>50)
    146. {
    147. digitalWrite(LED1,HIGH);
    148. digitalWrite(LED2, HIGH); // set the LED on
    149. digitalWrite(LED3,HIGH);
    150. digitalWrite(LED4, HIGH); // set the LED on
    151. digitalWrite(LED5,HIGH);
    152. digitalWrite(LED6,LOW);
    153. digitalWrite(LED7, LOW); // set the LED on
    154. digitalWrite(LED8,LOW);
    155. digitalWrite(LED9, LOW); // set the LED on
    156. digitalWrite(LED10,LOW);
    157. digitalWrite(LED11,LOW);
    158. digitalWrite(LED12, LOW); // set the LED on
    159. digitalWrite(LED13,LOW);
    160. digitalWrite(LED14, LOW); // set the LED on
    161. digitalWrite(LED15,LOW);
    162. digitalWrite(LED16,LOW);
    163. digitalWrite(LED17, LOW); // set the LED on
    164. digitalWrite(LED18,LOW);
    165. digitalWrite(LED19, LOW); // set the LED on
    166. digitalWrite(LED20,LOW);
    167. digitalWrite(LED21,LOW);
    168. }
    169. else if(soundav>40)
    170. {
    171. digitalWrite(LED1,HIGH);
    172. digitalWrite(LED2, HIGH); // set the LED on
    173. digitalWrite(LED3,HIGH);
    174. digitalWrite(LED4, HIGH); // set the LED on
    175. digitalWrite(LED5,LOW);
    176. digitalWrite(LED6,LOW);
    177. digitalWrite(LED7, LOW); // set the LED on
    178. digitalWrite(LED8,LOW);
    179. digitalWrite(LED9, LOW); // set the LED on
    180. digitalWrite(LED10,LOW);
    181. digitalWrite(LED11,LOW);
    182. digitalWrite(LED12, LOW); // set the LED on
    183. digitalWrite(LED13,LOW);
    184. digitalWrite(LED14, LOW); // set the LED on
    185. digitalWrite(LED15,LOW);
    186. digitalWrite(LED16,LOW);
    187. digitalWrite(LED17, LOW); // set the LED on
    188. digitalWrite(LED18,LOW);
    189. digitalWrite(LED19, LOW); // set the LED on
    190. digitalWrite(LED20,LOW);
    191. digitalWrite(LED21,LOW);
    192. }
    193. else if(soundav>30)
    194. {
    195. digitalWrite(LED1,HIGH);
    196. digitalWrite(LED2, HIGH); // set the LED on
    197. digitalWrite(LED3,HIGH);
    198. digitalWrite(LED4, LOW); // set the LED on
    199. digitalWrite(LED5,LOW);
    200. digitalWrite(LED6,LOW);
    201. digitalWrite(LED7, LOW); // set the LED on
    202. digitalWrite(LED8,LOW);
    203. digitalWrite(LED9, LOW); // set the LED on
    204. digitalWrite(LED10,LOW);
    205. digitalWrite(LED11,LOW);
    206. digitalWrite(LED12, LOW); // set the LED on
    207. digitalWrite(LED13,LOW);
    208. digitalWrite(LED14, LOW); // set the LED on
    209. digitalWrite(LED15,LOW);
    210. digitalWrite(LED16,LOW);
    211. digitalWrite(LED17, LOW); // set the LED on
    212. digitalWrite(LED18,LOW);
    213. digitalWrite(LED19, LOW); // set the LED on
    214. digitalWrite(LED20,LOW);
    215. digitalWrite(LED21,LOW);
    216. }
    217. else if(soundav>20)
    218. {
    219. digitalWrite(LED1,HIGH);
    220. digitalWrite(LED2, HIGH); // set the LED on
    221. digitalWrite(LED3,LOW);
    222. digitalWrite(LED4, LOW); // set the LED on
    223. digitalWrite(LED5,LOW);
    224. digitalWrite(LED6,LOW);
    225. digitalWrite(LED7, LOW); // set the LED on
    226. digitalWrite(LED8,LOW);
    227. digitalWrite(LED9, LOW); // set the LED on
    228. digitalWrite(LED10,LOW);
    229. digitalWrite(LED11,LOW);
    230. digitalWrite(LED12, LOW); // set the LED on
    231. digitalWrite(LED13,LOW);
    232. digitalWrite(LED14, LOW); // set the LED on
    233. digitalWrite(LED15,LOW);
    234. digitalWrite(LED16,LOW);
    235. digitalWrite(LED17, LOW); // set the LED on
    236. digitalWrite(LED18,LOW);
    237. digitalWrite(LED19, LOW); // set the LED on
    238. digitalWrite(LED20,LOW);
    239. digitalWrite(LED21,LOW);
    240. }
    241. else if(soundav>10)
    242. {
    243. digitalWrite(LED1,HIGH);
    244. digitalWrite(LED2, LOW); // set the LED on
    245. digitalWrite(LED3,LOW);
    246. digitalWrite(LED4, LOW); // set the LED on
    247. digitalWrite(LED5,LOW);
    248. digitalWrite(LED6,LOW);
    249. digitalWrite(LED7, LOW); // set the LED on
    250. digitalWrite(LED8,LOW);
    251. digitalWrite(LED9, LOW); // set the LED on
    252. digitalWrite(LED10,LOW);
    253. digitalWrite(LED11,LOW);
    254. digitalWrite(LED12, LOW); // set the LED on
    255. digitalWrite(LED13,LOW);
    256. digitalWrite(LED14, LOW); // set the LED on
    257. digitalWrite(LED15,LOW);
    258. digitalWrite(LED16,LOW);
    259. digitalWrite(LED17, LOW); // set the LED on
    260. digitalWrite(LED18,LOW);
    261. digitalWrite(LED19, LOW); // set the LED on
    262. digitalWrite(LED20,LOW);
    263. digitalWrite(LED21,LOW);
    264. }
    265. else
    266. {
    267. digitalWrite(LED1,LOW);
    268. digitalWrite(LED2, LOW); // set the LED on
    269. digitalWrite(LED3,LOW);
    270. digitalWrite(LED4, LOW); // set the LED on
    271. digitalWrite(LED5,LOW);
    272. digitalWrite(LED6,LOW);
    273. digitalWrite(LED7, LOW); // set the LED on
    274. digitalWrite(LED8,LOW);
    275. digitalWrite(LED9, LOW); // set the LED on
    276. digitalWrite(LED10,LOW);
    277. digitalWrite(LED11,LOW);
    278. digitalWrite(LED12, LOW); // set the LED on
    279. digitalWrite(LED13,LOW);
    280. digitalWrite(LED14, LOW); // set the LED on
    281. digitalWrite(LED15,LOW);
    282. digitalWrite(LED16,LOW);
    283. digitalWrite(LED17, LOW); // set the LED on
    284. digitalWrite(LED18,LOW);
    285. digitalWrite(LED19, LOW); // set the LED on
    286. digitalWrite(LED20,LOW);
    287. digitalWrite(LED21,LOW);
    288.  
    289. }
    290.  
    291. }
    292. }
    293. Serial.print(analogRead(soundpin)); //output for serial monitor
    294.  
    295. Serial.println(" ");
    296. delay(5);
    297. }
     
  5. Bosparra

    Member

    Feb 17, 2010
    79
    3
    That is allot of code.:eek:
    First of all, lets start by simplifying to logic a bit. I am not sure I understand exactly what you are trying to do, so stay with me, we will get there eventually. Lets start with just lighting the led's in sequence first.

    I do not have access to my Arduino environment right now, so I cannot test it, but this should get you started:
    Code ( (Unknown Language)):
    1.  
    2. loop()
    3. {
    4.   int val, i;
    5.   val = analogRead(analog_pin);
    6.  
    7.   val = map(val, 0, 1023, 1, 21);
    8.  
    9.   for(i=1; i<=21; i++)
    10.   {
    11.     if(i == 13)
    12.      continue;
    13.  
    14.    if(i<=val)
    15.      digitalWrite(i, HIGH);
    16.    else
    17.      digitalWrite(i, LOW);
    18.   }
    19. }
    20.  
    21.  
    Let me know what you see.
     
  6. Turkish

    Thread Starter New Member

    May 16, 2010
    24
    0
  7. dasraiser

    New Member

    Sep 1, 2010
    5
    0
    hi what about void loop() as the function is non return?
     
  8. Bosparra

    Member

    Feb 17, 2010
    79
    3
    The 'void' was omitted by mistake, like I said, I was unable to compile at the time. I figured it should be straight forward since you already have the loop statement in your previous code. You have to use the reference manual, seriously, its all in there on the first page! Click on Help->Reference.

    For clarity sake, the code I gave, should replace the code in your existing loop statement. Leave the setup code as is for now. Just replace whatever you have INSIDE your loop function, with is INSIDE my loop function. Also check the variable name passed in my the analogRead() statement, I just made something up that is meant to be replaced by whatever name you are using. If you get any compile errors, by all means, the reference manual is your friend.;)

    Also consider a slight delay, of say 15ms at the end of the loop, in order to give the ADC time to stabilize before the next reading.
     
  9. texarkaggie

    New Member

    Nov 10, 2013
    1
    0
    wow this really helped me figure out arrays for controlling LEDs!!
     
Loading...