Advertisement
gnamp

Rank Ranger Dominic gnamp

Apr 25th, 2017
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1. #define trigPin 3
  2. #define echoPin 2
  3.  
  4. void setup(){
  5. Serial.begin(9600);
  6. pinMode(trigPin, OUTPUT);
  7. pinMode(echoPin, INPUT);
  8. }
  9.  
  10. void loop(){
  11. int duration, distance;
  12. digitalWrite(trigPin, HIGH);
  13. delayMicroseconds(1000);
  14. digitalWrite(trigPin, LOW);
  15. duration = pulseIn(echoPin, HIGH);
  16. distance = (duration / 2) / 29.1;
  17. Serial.print(distance);
  18. Serial.println(" cm");
  19.  
  20. //
  21.  
  22. int thisPitch = map(distance, 0, 200, 2093, 22);
  23. int standardPitch = 1500;
  24.  
  25. // noteList
  26.  
  27. int noteC0 = 262;
  28. int noteC0sharp = 278;
  29. int noteD0 = 294;
  30. int noteD0sharp = 312;
  31. int noteE0 = 330;
  32. int noteF0 = 349;
  33. int noteF0sharp = 370.5;
  34. int noteG0 = 392;
  35. int noteG0sharp = 416;
  36. int noteA1 = 440;
  37. int noteA1sharp = 467;
  38. int noteB1 = 494;
  39. int noteC1 = 523;
  40. int noteC1sharp = 555;
  41. int noteD1 = 587;
  42. int noteD1sharp = 623;
  43. int noteE1 = 659;
  44. int noteF1 = 698;
  45. int noteF1sharp = 741;
  46. int noteG1 = 784;
  47. int noteG1sharp = 832;
  48. int noteA2 = 880;
  49. int noteA2sharp = 934;
  50. int noteB2 = 988;
  51. int noteC2 = 1047;
  52.  
  53.  
  54. //----------------
  55. //settings here
  56.  
  57.  
  58. if (distance > 150)
  59. {
  60. // tunes/tones here:-
  61.  
  62.  
  63. // wark wark
  64.  
  65. tone(4, noteG0); //1
  66. delay(100);
  67. noTone(4);
  68. delay(100);
  69. tone(4, noteE0); //2
  70. delay(100);
  71. noTone(4);
  72. delay(10000);
  73.  
  74.  
  75. /*
  76. //Illegal car horn
  77.  
  78. tone(4, noteG0); //1
  79. delay(100);
  80. noTone(4);
  81. delay(100);
  82. tone(4, noteE0); //2
  83. delay(100);
  84. noTone(4);
  85. delay(100);
  86. tone(4, noteF0); //3
  87. delay(100);
  88. noTone(4);
  89. delay(100);
  90. tone(4, noteG0); //4
  91. delay(100);
  92. noTone(4);
  93. delay(100);
  94. tone(4, noteG0); //5
  95. delay(100);
  96. noTone(4);
  97. delay(100);
  98.  
  99. tone(4, noteE1); //6
  100. delay(100);
  101. noTone(4);
  102. delay(100);
  103. tone(4, noteE1); //7
  104. delay(100);
  105. noTone(4);
  106. delay(100);
  107. tone(4, noteC1); //8
  108. delay(400);
  109. noTone(4);
  110. delay(800);
  111. */ //end of Illegal Car Horn
  112.  
  113. //dukes of hazard
  114. /*
  115. tone(4, noteE0); //1
  116. delay(100);
  117. noTone(4);
  118. delay(100);
  119. tone(4, noteD0); //2
  120. delay(100);
  121. noTone(4);
  122. delay(100);
  123. tone(4, noteC0); //3
  124. delay(300);
  125. noTone(4);
  126. delay(100);
  127. tone(4, noteC0); //4
  128. delay(300);
  129. noTone(4);
  130. delay(100);
  131. tone(4, noteC0); //5
  132. delay(100);
  133. noTone(4);
  134. delay(100);
  135. tone(4, noteD0); //6
  136. delay(100);
  137. noTone(4);
  138. delay(100);
  139. tone(4, noteE0); //7
  140. delay(100);
  141. noTone(4);
  142. delay(100);
  143. tone(4, noteF0); //8
  144. delay(100);
  145. noTone(4);
  146. delay(100);
  147. tone(4, noteG0); //9
  148. delay(300);
  149. noTone(4);
  150. delay(100);
  151. tone(4, noteG0); //10
  152. delay(300);
  153. noTone(4);
  154. delay(100);
  155. tone(4, noteG0); //11
  156. delay(300);
  157. noTone(4);
  158. delay(100);
  159. tone(4, noteE0); //12
  160. delay(400);
  161. noTone(4);
  162. delay(6000);
  163.  
  164. */ //end of Dukes of Hazard
  165.  
  166. //---------------------------
  167. /*
  168. //Harlem Shake
  169.  
  170. tone(4, noteE0); //1
  171. delay(100);
  172. noTone(4);
  173. delay(100);
  174. tone(4, noteF0); //2
  175. delay(100);
  176. noTone(4);
  177. delay(100);
  178. tone(4, noteF0); //3
  179. delay(100);
  180. noTone(4);
  181. delay(100);
  182. tone(4, noteF0); //4
  183. delay(100);
  184. noTone(4);
  185. delay(100);
  186. tone(4, noteF0); //5
  187. delay(300);
  188. noTone(4);
  189. delay(100);
  190.  
  191. tone(4, noteF0); //6
  192. delay(100);
  193. noTone(4);
  194. delay(100);
  195. tone(4, noteF0); //7
  196. delay(100);
  197. noTone(4);
  198. delay(100);
  199. tone(4, noteF0); //8
  200. delay(100);
  201. noTone(4);
  202. delay(100);
  203. tone(4, noteF0); //9
  204. delay(150);
  205. noTone(4);
  206. delay(50);
  207. tone(4, noteF0); //10 half note #1
  208. delay(50);
  209. noTone(4);
  210. delay(50);
  211. tone(4, noteF0); //11 half note #2
  212. delay(50);
  213. noTone(4);
  214. delay(50);
  215. tone(4, noteF0); //12
  216. delay(100);
  217. noTone(4);
  218. delay(100);
  219. tone(4, noteF0); //13
  220. delay(100);
  221. noTone(4);
  222. delay(100);
  223. tone(4, noteD0sharp); //14
  224. delay(100);
  225. noTone(4);
  226. delay(100);
  227. tone(4, noteE0); //15
  228. delay(100);
  229. noTone(4);
  230. delay(100);
  231. tone(4, noteF0); //16
  232. delay(100);
  233. noTone(4);
  234. delay(100);
  235. // end of Harlem Shake
  236. */
  237.  
  238.  
  239. //Harlem Shake x3
  240.  
  241. tone(4, noteE0); //1 (first playthrough)
  242. delay(100);
  243. noTone(4);
  244. delay(100);
  245. tone(4, noteF0); //2
  246. delay(100);
  247. noTone(4);
  248. delay(100);
  249. tone(4, noteF0); //3
  250. delay(100);
  251. noTone(4);
  252. delay(100);
  253. tone(4, noteF0); //4
  254. delay(100);
  255. noTone(4);
  256. delay(100);
  257. tone(4, noteF0); //5
  258. delay(300);
  259. noTone(4);
  260. delay(100);
  261.  
  262. tone(4, noteF0); //6
  263. delay(100);
  264. noTone(4);
  265. delay(100);
  266. tone(4, noteF0); //7
  267. delay(100);
  268. noTone(4);
  269. delay(100);
  270. tone(4, noteF0); //8
  271. delay(100);
  272. noTone(4);
  273. delay(100);
  274. tone(4, noteF0); //9
  275. delay(150);
  276. noTone(4);
  277. delay(50);
  278. tone(4, noteF0); //10 half note #1
  279. delay(50);
  280. noTone(4);
  281. delay(50);
  282. tone(4, noteF0); //11 half note #2
  283. delay(50);
  284. noTone(4);
  285. delay(50);
  286. tone(4, noteF0); //12
  287. delay(100);
  288. noTone(4);
  289. delay(100);
  290. tone(4, noteF0); //13
  291. delay(100);
  292. noTone(4);
  293. delay(100);
  294. tone(4, noteD0sharp); //14
  295. delay(100);
  296. noTone(4);
  297. delay(100);
  298. tone(4, noteE0); //15
  299. delay(100);
  300. noTone(4);
  301. delay(100);
  302. tone(4, noteF0); //16
  303. delay(100);
  304. noTone(4);
  305. delay(100);
  306.  
  307. tone(4, noteE0); //1 (second playthrough)
  308. delay(100);
  309. noTone(4);
  310. delay(100);
  311. tone(4, noteF0); //2
  312. delay(100);
  313. noTone(4);
  314. delay(100);
  315. tone(4, noteF0); //3
  316. delay(100);
  317. noTone(4);
  318. delay(100);
  319. tone(4, noteF0); //4
  320. delay(100);
  321. noTone(4);
  322. delay(100);
  323. tone(4, noteF0); //5
  324. delay(300);
  325. noTone(4);
  326. delay(100);
  327.  
  328. tone(4, noteF0); //6
  329. delay(100);
  330. noTone(4);
  331. delay(100);
  332. tone(4, noteF0); //7
  333. delay(100);
  334. noTone(4);
  335. delay(100);
  336. tone(4, noteF0); //8
  337. delay(100);
  338. noTone(4);
  339. delay(100);
  340. tone(4, noteF0); //9
  341. delay(150);
  342. noTone(4);
  343. delay(50);
  344. tone(4, noteF0); //10 half note #1
  345. delay(50);
  346. noTone(4);
  347. delay(50);
  348. tone(4, noteF0); //11 half note #2
  349. delay(50);
  350. noTone(4);
  351. delay(50);
  352. tone(4, noteF0); //12
  353. delay(100);
  354. noTone(4);
  355. delay(100);
  356. tone(4, noteF0); //13
  357. delay(100);
  358. noTone(4);
  359. delay(100);
  360. tone(4, noteD0sharp); //14
  361. delay(100);
  362. noTone(4);
  363. delay(100);
  364. tone(4, noteE0); //15
  365. delay(100);
  366. noTone(4);
  367. delay(100);
  368. tone(4, noteF0); //16
  369. delay(100);
  370. noTone(4);
  371. delay(100);
  372.  
  373. tone(4, noteE0); //1 (third playthrough)
  374. delay(100);
  375. noTone(4);
  376. delay(100);
  377. tone(4, noteF0); //2
  378. delay(100);
  379. noTone(4);
  380. delay(100);
  381. tone(4, noteF0); //3
  382. delay(100);
  383. noTone(4);
  384. delay(100);
  385. tone(4, noteF0); //4
  386. delay(100);
  387. noTone(4);
  388. delay(100);
  389. tone(4, noteF0); //5
  390. delay(300);
  391. noTone(4);
  392. delay(100);
  393.  
  394. tone(4, noteF0); //6
  395. delay(100);
  396. noTone(4);
  397. delay(100);
  398. tone(4, noteF0); //7
  399. delay(100);
  400. noTone(4);
  401. delay(100);
  402. tone(4, noteF0); //8
  403. delay(100);
  404. noTone(4);
  405. delay(100);
  406. tone(4, noteF0); //9
  407. delay(150);
  408. noTone(4);
  409. delay(50);
  410. tone(4, noteF0); //10 half note #1
  411. delay(50);
  412. noTone(4);
  413. delay(50);
  414. tone(4, noteF0); //11 half note #2
  415. delay(50);
  416. noTone(4);
  417. delay(50);
  418. tone(4, noteF0); //12
  419. delay(100);
  420. noTone(4);
  421. delay(100);
  422. tone(4, noteF0); //13
  423. delay(100);
  424. noTone(4);
  425. delay(100);
  426. tone(4, noteD0sharp); //14
  427. delay(100);
  428. noTone(4);
  429. delay(100);
  430. tone(4, noteE0); //15
  431. delay(100);
  432. noTone(4);
  433. delay(100);
  434. tone(4, noteF0); //16
  435. delay(100);
  436. noTone(4);
  437. delay(100);
  438.  
  439. // end of Harlem shake x3
  440.  
  441. }
  442.  
  443. noTone(4);
  444. delay(1);
  445. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement