p5_neuron_car.ino 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. #include "Arduino.h"
  2. #include <Servo.h>
  3. Servo myservo;
  4. #define Port7 7 //for TFT_ILI9163C_CSpin 7
  5. #define Port8 8 //for TFT_ILI9163C_DCpin 8
  6. #define Port9 9 //for TFT_ILI9163C__RSTpin 9
  7. // #define TFT_ILI9163C_CSpin Port7 // 7 // __CSpin // 53 // 10 // chip select
  8. #include "__main_struct.h" //lite #include "___main/__main_struct.h"
  9. #include "progmem.h"
  10. #include "__main_struct_limits.h"
  11. #include "_PortTypes_struct.h"
  12. #include "_Port_Exp_state_ttl_struct.h"
  13. #include "_Port_Broadcast_state_struct.h"
  14. #include "_PortStates_struct.h"
  15. #include "_Port_I2C_driver_struct.h"
  16. #include "config_Active_ControllerID.h"
  17. #include "config_Slave_Ports_LOCAL_config.h" //lite
  18. #if defined(HAS_RF24)
  19. #include "RF24_config.h"
  20. #endif
  21. #if ! defined(TFT_ILI9163C_DCpin)
  22. #define TFT_ILI9163C_DCpin Port8 //8 // A0 data/command pin. sometimes called DC, RS, ...
  23. #endif
  24. #if ! defined(TFT_ILI9163C__RSTpin)
  25. #define TFT_ILI9163C__RSTpin Port9 //9 //reset pin. you must connect. (or pullup)
  26. #endif
  27. #include "automation_driven.submodule.struct.write_neuron.h"
  28. #if defined(HAS_LCD1602_I2C)
  29. #include <LiquidCrystal_I2C.h>
  30. LiquidCrystal_I2C lcd(0x27,LCD1602_DISPLAY_PHYSICAL_X_CHARS_A,LCD1602_DISPLAY_PHYSICAL_Y_CHARS_A);
  31. #endif
  32. #if defined(HAS_TFT_ILI9163C)
  33. #include "_TFT_ILI9163C_config.h"
  34. // #include "_TFT_ILI9163C_struct.h"
  35. bool DISPLAY_PHYS_A_set() {
  36. DISPLAY_PHYS_A[0].X = 128 ;
  37. DISPLAY_PHYS_A[0].Y = 128 ;
  38. }
  39. bool DISPLAY_PHYS_A_set_init = DISPLAY_PHYS_A_set();
  40. TFT_ILI9163C DISPLAY_DEV = TFT_ILI9163C(TFT_ILI9163C_CSpin, TFT_ILI9163C_DCpin, TFT_ILI9163C__RSTpin); //#include "_TFT_ILI9163C_func.h"
  41. #elif defined(HAS_TFT_HX8357)
  42. #include <TFT_HX8357.h>
  43. // #error test
  44. TFT_HX8357 DISPLAY_DEV = TFT_HX8357(); // Invoke custom library
  45. bool DISPLAY_PHYS_A_set() {
  46. DISPLAY_PHYS_A[0].X = 320 ;
  47. DISPLAY_PHYS_A[0].Y = 240 ;
  48. }
  49. bool DISPLAY_PHYS_A_set_init = DISPLAY_PHYS_A_set();
  50. #endif
  51. #if defined(HAS_BH1750)
  52. #include <Wire.h> //BH1750 IIC Mode
  53. #include <math.h>
  54. int BH1750address = 0x23; //setting i2c address
  55. byte BH1750_buff[2];
  56. bool if_BH1750_Init = 0 ;
  57. void BH1750_Init(int address)
  58. {
  59. Wire.beginTransmission(address);
  60. Wire.write(0x10);//1lx reolution 120ms
  61. Wire.endTransmission();
  62. }
  63. int BH1750_Read(int address) //
  64. {
  65. int i=0;
  66. Wire.beginTransmission(address);
  67. Wire.requestFrom(address, 2);
  68. while(Wire.available()) //
  69. {
  70. BH1750_buff[i] = Wire.read(); // receive one byte
  71. i++;
  72. }
  73. Wire.endTransmission();
  74. return i;
  75. }
  76. #endif
  77. #if defined(HAS_W5IOKeypad)
  78. #include <W5IOKeypad.h>
  79. #endif
  80. #if defined(HAS__PCINT_setup)
  81. #include "_PCINT_struct.h" //pins MYPIN1 MYPIN2 MYPIN3
  82. #endif
  83. #if defined(HAS_ROTTARY_SW)
  84. #include "_ROTTARY_SW_config.h" //_ROTTARY_SW/
  85. #endif
  86. #if defined(HAS_ROTTARY_SW)
  87. #include "_ROTTARY_SW_struct.h" //lite _ROTTARY_SW/
  88. #else
  89. int encoderPos = 0 ;
  90. int oldEncPos = 0 ;
  91. int triggerCount = 0 ;
  92. int triggerCountOld = 0 ;
  93. #endif
  94. #if defined(HAS_ROTTARY_SW)
  95. #include "_ROTTARY_SW_func.h" //lite _ROTTARY_SW/
  96. #endif
  97. #if defined(HAS__PCINT_setup)
  98. #include "_PCINT_init.h"
  99. #endif
  100. //#include "config_Slave_Ports_LOCAL_init.h"
  101. #include "automation_driven.submodule.struct.write_neuron_override.h"
  102. #include "neuron-conf.h"
  103. #include "config_Slave_Ports_LOCAL_neuron_config.h"
  104. #include "neuron_Input_func.h"
  105. #include "neuron_Stress_func.h"
  106. #include "neuron_Attract_func.h"
  107. #include "neuron_PORT_to_NEURON_func.h"
  108. #include "neuron_Resting_Potenial_func.h"
  109. #include "_TASK_TYPES_struct.h"
  110. bool neuron_print_ROTTARY_Coordinate_Y_SHIFT_flag = 0 ;
  111. #include "automation_driven.submodule.struct.write_neuron.lcd_menu.h"
  112. #include "Simulated_potential_show_lcd.h"
  113. #include "_time_struct.h"
  114. #if defined(HAS_ADKeyboard)
  115. #include "ADKeyboard.h"
  116. #endif
  117. #if defined(HAS_TFT_HX8357) || defined(HAS_TFT_ILI9163C)
  118. #include "neuron_print.h"
  119. #endif
  120. // bool if_show_p0_neuron_title = 0 ;
  121. #include "TASK_TYPE_T_Get_Ports_Status_INPUT_A___.h"
  122. #include "_Slave_Ports_Status_func_add_lite.h"
  123. #if Active_ControllerID == 0x14
  124. #include "0x14/config_Slave_Ports_LOCAL_0x14_init.h"
  125. #elif Active_ControllerID == 0x35
  126. #include "0x35/config_Slave_Ports_neuron_LOCAL_0x35_init.h"
  127. #elif Active_ControllerID == 0x38
  128. #include "0x38/config_Slave_Ports_LOCAL_0x38_init.h"
  129. #elif Active_ControllerID == 0x42
  130. #include "0x42/config_Slave_Ports_LOCAL_0x42_init.h"
  131. #else
  132. #error not set correct Active_ControllerID
  133. #endif
  134. #if defined(HAS_W5IOKeypad)
  135. W5IOKeypad Keypad( W5IOKeypad_PIN_GND, W5IOKeypad_PIN_IO1, W5IOKeypad_PIN_IO2, W5IOKeypad_PIN_IO3, W5IOKeypad_PIN_IO4, W5IOKeypad_PIN_IO5 );
  136. int IOKey = 0;
  137. int IOKey_last = 0;
  138. #endif
  139. void action_button_input( ) {
  140. #if defined(HAS_W5IOKeypad)
  141. for(int i=0; i<20;i++) {
  142. lcd.setCursor(i,1);
  143. if(IOKey == i+1) {
  144. if(IOKey == 11) {//11 l
  145. lcd_menu__action_button_input__left() ;
  146. } else if(IOKey == 12) { //12 up
  147. lcd_menu__action_button_input__up() ;
  148. } else if(IOKey == 13) { //13 fire
  149. lcd_menu__action_button_input__toggle() ;
  150. } else if(IOKey == 14) { //14 dol
  151. lcd_menu__action_button_input__down();
  152. } else if(IOKey == 15) { //15 r
  153. lcd_menu__action_button_input__right() ;
  154. } else {
  155. lcd.print("+");
  156. //NEURON_A[i].Simulated_potential = NEURON_A[i].Simulated_potential + ( action_button_input_Maximum_current * action_button_input_Time_constant ) / NEURON_A[i].Capacitance ;
  157. neuron_Input(i,neuron_Logic_A[0].action_button_input_Time_constant , neuron_Logic_A[0].action_button_input_Maximum_current, 0 );
  158. Serial.print(F(" ")); Serial.print(NEURON_A[i].Simulated_potential);
  159. }
  160. } else lcd.print(" ");
  161. }
  162. #elif defined(HAS_ADKeyboard)
  163. if(IOKey == 1) {
  164. lcd_menu__action_button_input__right() ;
  165. } else if(IOKey == 2) {
  166. lcd_menu__action_button_input__down();
  167. } else if(IOKey == 3) {
  168. lcd_menu__action_button_input__up() ;
  169. } else if(IOKey == 4) {
  170. lcd_menu__action_button_input__left() ;
  171. } else if(IOKey == 5) {
  172. lcd_menu__action_button_input__toggle() ;
  173. }
  174. #endif
  175. }
  176. #include "neuron_PCF8574.h"
  177. #if defined(HAS_HCSR04)
  178. #include "HC-SR04.h"
  179. #endif
  180. void setup() { //REMEMBER NOT INITIALIZE ANY VARIABLES OR ARRAYS
  181. Serial.begin(115200);
  182. lcd.init(); // Print a message to the LCD.
  183. lcd.backlight();
  184. lcd.setCursor(0,0);
  185. //lcd.print("debug neuron ");
  186. #if defined(HAS_TFT_HX8357)
  187. DISPLAY_DEV.init();
  188. DISPLAY_DEV.setRotation(1);
  189. #elif defined(HAS_TFT_ILI9163C)
  190. DISPLAY_DEV.begin();
  191. #endif
  192. #if defined(HAS_TFT_HX8357) || defined(HAS_TFT_ILI9163C)
  193. // DISPLAY_DEV.setRotation(2);
  194. DISPLAY_DEV.fillScreen(BLACK);//DISPLAY_DEV.clearScreen();
  195. DISPLAY_DEV.setCursor(0,0);
  196. #endif
  197. #if defined(HAS__PCINT_setup)
  198. #include "_PCINT_setup.h" //empty
  199. #endif
  200. #if defined(HAS_ROTTARY_SW)
  201. #include "_ROTTARY_SW_setup.h" //Attach interrupts //lite _ROTTARY_SW/
  202. #endif
  203. show_p0_neuron_title();
  204. /*
  205. pinMode(AnalogSensorLL_PIN, INPUT_PULLUP);
  206. pinMode(AnalogSensorLC_PIN, INPUT_PULLUP);
  207. pinMode(AnalogSensorRC_PIN, INPUT_PULLUP);
  208. pinMode(AnalogSensorRR_PIN, INPUT_PULLUP);
  209. */
  210. TASK_TYPE_T_Get_Ports_Status_INPUT_A___SETUP();
  211. #if defined(PWM_Servo_PIN)
  212. myservo.attach(PWM_Servo_PIN);
  213. myservo.write(90);
  214. #endif
  215. #if defined(HAS_HCSR04)
  216. pinMode(HCSR04_trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
  217. pinMode(HCSR04_echoPin, INPUT); // Sets the echoPin as an INPUT
  218. #endif
  219. #if defined(HAS_ADKeyboard)
  220. // pinMode(ADKeyboard_PIN, INPUT_PULLUP) ;
  221. #endif
  222. #if defined(HAS_BH1750)
  223. Wire.begin();
  224. #endif
  225. #if defined(HAS_RF24)
  226. #include "RF24_setup.h"
  227. #endif
  228. // pinMode(11, OUTPUT);
  229. // pinMode(13, OUTPUT);
  230. // pinMode(3, OUTPUT);
  231. // pinMode(5, OUTPUT);
  232. // pinMode(A7, OUTPUT);
  233. // pinMode(13, OUTPUT);
  234. // digitalWrite(13,LOW);
  235. // pinMode(A6, INPUT) ;
  236. }
  237. void loop() {
  238. #include "p5_neuron_car_loop.h"
  239. if(NEURON_TO_PORT_A_INDEX_NEXT > NEURON_TO_PORT_A_LIMIT) { SPFTFT2(limit,error,-321); SPFTFT2(value,error, NEURON_TO_PORT_A_INDEX_NEXT - NEURON_TO_PORT_A_LIMIT ) ;}
  240. if(PORT_to_NEURON_A_INDEX_NEXT > PORT_to_NEURON_A_LIMIT) { SPFTFT2(limit,error,-322); SPFTFT2(value,error, PORT_to_NEURON_A_INDEX_NEXT - PORT_to_NEURON_A_LIMIT ) ; }
  241. // digitalWrite(31,HIGH);
  242. // digitalWrite(33,HIGH);
  243. //SPFTFT2(level,debug,analogRead(A6));
  244. if(triggerCount != triggerCountOld) {
  245. SPFTFT2(rottary,trigger,triggerCount);
  246. if(triggerCountOld_t < millis()) {
  247. triggerCountOld_t = millis() + 500 ;
  248. triggerCountOld = triggerCount ;
  249. } else {
  250. SPFTFTFTFT(rottary,trigger,time,bypassed);
  251. triggerCountOld = triggerCount ;
  252. }
  253. }
  254. // if(if_show_p0_neuron_title == 0) show_p0_neuron_title() ;
  255. // Serial.print(F("R"));
  256. #if defined(HAS_HCSR04)
  257. HCSR04_input();
  258. #endif
  259. #if defined(HAS_RF24) and HAS_RF24 == 1
  260. #include "RF24_RX_loop.h"
  261. #endif
  262. neuron_PORT_to_NEURON();
  263. neuron_Resting_Potenial_input();
  264. neuron_Resting_Potenial();
  265. // Serial.print(F("C"));
  266. Simulated_potential_show_lcd();
  267. // Serial.print(F("P"));
  268. #if defined(HAS_TFT_HX8357) || defined(HAS_TFT_ILI9163C)
  269. neuron_print();
  270. #endif
  271. TASK_TYPE_T_Get_Ports_Status_INPUT_A___LOOP();
  272. #if defined(HAS_W5IOKeypad)
  273. // Serial.print(F("K"));
  274. IOKey=Keypad.ReadButtons();
  275. if(IOKey == 0) {
  276. IOKey_last = IOKey ;
  277. } else if(IOKey_last == IOKey and IOKey != 0) {
  278. // Serial.print(F("K"));
  279. } else {
  280. IOKey_last = IOKey ;
  281. Serial.println(IOKey);
  282. Serial.print(F("A"));
  283. action_button_input();
  284. }
  285. #elif defined(HAS_ADKeyboard)
  286. if(ADKeyboard_get_key_t > millis()) {
  287. } else if(ADKeyboard_get_key()>0 and ADKeyboard_get_key_delay_t < millis()) {
  288. ADKeyboard_get_key_delay_t = millis() + 100 ;
  289. } else {
  290. IOKey=ADKeyboard_get_key();
  291. if(IOKey == 0) {
  292. IOKey_last = IOKey ;
  293. } else if(IOKey_last == IOKey and IOKey != 0) {
  294. } else {
  295. ADKeyboard_get_key_t = millis() + 300 ;
  296. IOKey_last = IOKey ;
  297. Serial.println(IOKey);
  298. Serial.print(F(" A "));
  299. SPFT2(input,analogRead(ADKeyboard_PIN));
  300. action_button_input();
  301. }
  302. }
  303. #endif
  304. }