p5_neuron.ino 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. #if ! defined(TFT_ILI9163C_DCpin)
  9. #define TFT_ILI9163C_DCpin Port8 //8 // A0 data/command pin. sometimes called DC, RS, ...
  10. #endif
  11. #if ! defined(TFT_ILI9163C__RSTpin)
  12. #define TFT_ILI9163C__RSTpin Port9 //9 //reset pin. you must connect. (or pullup)
  13. #endif
  14. #include "__main_struct.h" //lite #include "___main/__main_struct.h"
  15. #include "progmem.h"
  16. #include "__main_struct_limits.h"
  17. #include "config_Active_ControllerID.h"
  18. #include "config_Slave_Ports_LOCAL_config.h" //lite
  19. #include "automation_driven.submodule.struct.write_neuron.h"
  20. #if defined(HAS_LCD1602_I2C)
  21. #include <LiquidCrystal_I2C.h>
  22. LiquidCrystal_I2C lcd(0x27,LCD1602_DISPLAY_PHYSICAL_X_CHARS_A,LCD1602_DISPLAY_PHYSICAL_Y_CHARS_A);
  23. #endif
  24. #if defined(HAS_TFT_ILI9163C)
  25. #include "_TFT_ILI9163C_config.h"
  26. // #include "_TFT_ILI9163C_struct.h"
  27. bool DISPLAY_PHYS_A_set() {
  28. DISPLAY_PHYS_A[0].X = 128 ;
  29. DISPLAY_PHYS_A[0].Y = 128 ;
  30. }
  31. bool DISPLAY_PHYS_A_set_init = DISPLAY_PHYS_A_set();
  32. TFT_ILI9163C DISPLAY_DEV = TFT_ILI9163C(TFT_ILI9163C_CSpin, TFT_ILI9163C_DCpin, TFT_ILI9163C__RSTpin); //#include "_TFT_ILI9163C_func.h"
  33. #elif defined(HAS_TFT_HX8357)
  34. #include <TFT_HX8357.h>
  35. // #error test
  36. TFT_HX8357 DISPLAY_DEV = TFT_HX8357(); // Invoke custom library
  37. bool DISPLAY_PHYS_A_set() {
  38. DISPLAY_PHYS_A[0].X = 240 ;
  39. DISPLAY_PHYS_A[0].Y = 320 ;
  40. }
  41. bool DISPLAY_PHYS_A_set_init = DISPLAY_PHYS_A_set();
  42. #endif
  43. #if defined(HAS_W5IOKeypad)
  44. #include <W5IOKeypad.h>
  45. #endif
  46. #if defined(HAS__PCINT_setup)
  47. #include "_PCINT_struct.h" //pins MYPIN1 MYPIN2 MYPIN3
  48. #endif
  49. #if defined(HAS_ROTTARY_SW)
  50. #include "_ROTTARY_SW_config.h" //_ROTTARY_SW/
  51. #endif
  52. #if defined(HAS_ROTTARY_SW)
  53. #include "_ROTTARY_SW_struct.h" //lite _ROTTARY_SW/
  54. #else
  55. int encoderPos = 0 ;
  56. int oldEncPos = 0 ;
  57. int triggerCount = 0 ;
  58. int triggerCountOld = 0 ;
  59. #endif
  60. #if defined(HAS_ROTTARY_SW)
  61. #include "_ROTTARY_SW_func.h" //lite _ROTTARY_SW/
  62. #endif
  63. #if defined(HAS__PCINT_setup)
  64. #include "_PCINT_init.h"
  65. #endif
  66. #include "neuron-conf.h"
  67. #include "neuron_Input_func.h"
  68. #include "neuron_Attract_func.h"
  69. #include "neuron_Resting_Potenial_func.h"
  70. #include "Simulated_potential_show_lcd.h"
  71. #include "neuron_print.h"
  72. // bool if_show_p0_neuron_title = 0 ;
  73. #if defined(HAS_W5IOKeypad)
  74. W5IOKeypad Keypad( W5IOKeypad_PIN_GND, W5IOKeypad_PIN_IO1, W5IOKeypad_PIN_IO2, W5IOKeypad_PIN_IO3, W5IOKeypad_PIN_IO4, W5IOKeypad_PIN_IO5 );
  75. int IOKey = 0;
  76. int IOKey_last = 0;
  77. #endif
  78. void action_button_input( ) {
  79. #if defined(HAS_W5IOKeypad)
  80. for(int i=0; i<20;i++) {
  81. lcd.setCursor(i,1);
  82. if(IOKey == i+1) {
  83. lcd.print("+");
  84. //NEURON_A[i].Simulated_potential = NEURON_A[i].Simulated_potential + ( action_button_input_Maximum_current * action_button_input_Time_constant ) / NEURON_A[i].Capacitance ;
  85. neuron_Input(i,action_button_input_Time_constant,action_button_input_Maximum_current, 0 );
  86. Serial.print(F(" ")); Serial.print(NEURON_A[i].Simulated_potential);
  87. } else lcd.print(" ");
  88. }
  89. #endif
  90. }
  91. #include "neuron_PCF8574.h"
  92. void setup() { //REMEMBER NOT INITIALIZE ANY VARIABLES OR ARRAYS
  93. Serial.begin(115200);
  94. lcd.init(); // Print a message to the LCD.
  95. lcd.backlight();
  96. lcd.setCursor(0,0);
  97. //lcd.print("debug neuron ");
  98. #if defined(HAS_TFT_HX8357)
  99. DISPLAY_DEV.init();
  100. #else
  101. DISPLAY_DEV.begin();
  102. #endif
  103. // DISPLAY_DEV.setRotation(2);
  104. DISPLAY_DEV.fillScreen(BLACK);//DISPLAY_DEV.clearScreen();
  105. DISPLAY_DEV.setCursor(0,0);
  106. #if defined(HAS__PCINT_setup)
  107. #include "_PCINT_setup.h" //empty
  108. #endif
  109. #if defined(HAS_ROTTARY_SW)
  110. #include "_ROTTARY_SW_setup.h" //Attach interrupts //lite _ROTTARY_SW/
  111. #endif
  112. show_p0_neuron_title();
  113. pinMode(AnalogSensorLL_PIN, INPUT_PULLUP);
  114. pinMode(AnalogSensorLC_PIN, INPUT_PULLUP);
  115. pinMode(AnalogSensorRC_PIN, INPUT_PULLUP);
  116. pinMode(AnalogSensorRR_PIN, INPUT_PULLUP);
  117. myservo.attach(PWM_Servo_PIN);
  118. myservo.write(90);
  119. }
  120. void loop() {
  121. // Serial.println(F("L"));
  122. if(triggerCount != triggerCountOld) {
  123. SPFTFT2(rottary,trigger,triggerCount);
  124. if(triggerCountOld_t < millis()) {
  125. triggerCountOld_t = millis() + 500 ;
  126. triggerCountOld = triggerCount ;
  127. } else {
  128. SPFTFTFTFT(rottary,trigger,time,bypassed);
  129. triggerCountOld = triggerCount ;
  130. }
  131. }
  132. // if(if_show_p0_neuron_title == 0) show_p0_neuron_title() ;
  133. // Serial.print(F("R"));
  134. neuron_Resting_Potenial();
  135. // Serial.print(F("C"));
  136. Simulated_potential_show_lcd();
  137. // Serial.print(F("P"));
  138. neuron_print();
  139. #if defined(HAS_W5IOKeypad)
  140. // Serial.print(F("K"));
  141. IOKey=Keypad.ReadButtons();
  142. if(IOKey == 0) {
  143. IOKey_last = IOKey ;
  144. } else if(IOKey_last == IOKey and IOKey != 0) {
  145. // Serial.print(F("K"));
  146. } else {
  147. IOKey_last = IOKey ;
  148. Serial.println(IOKey);
  149. Serial.print(F("A"));
  150. action_button_input();
  151. }
  152. #endif
  153. // delay(100);
  154. }