I will show you 2 coding walkthroughs, both do the same thing: they send a byte to an Arduino from the laptop/Raspberri Pi
here is the Arduino code (the same in both cases):
int ledPin = 13;
void setup() {
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
digitalWrite(ledPin,LOW);
}
void loop() {
if (Serial.read() == 'T'){
digitalWrite(ledPin,HIGH);}
}
it's a hello world. all it does is light up the default built in led (pin 13).
here is the way most NPCs code it(python code):
ser = serial.Serial("COM4", 9600,timeout=1.0)
time.sleep(3)
ser.reset_input_buffer()
ser.write(b'T')
print("ok")
time.sleep(2)
ser.close()
they also need to add the import statement:
import serial
here is my suggested alternative way:
neo:Chobits = Chobits()
neo.addSkill(DiArduino1())
neo.think("sr T", "", "")
time.sleep(2)
neo.think("close serial", "", "")
in my way all I need to add to get the laptop to Arduino communication ability is 1 line of code:
neo.addSkill(DiArduino1())
I can send any char via the ear param: "sr V" or "sr T" for example
I need not concern myself with the logic or the hardware code.
the skill also has a close serial capability.
I can easily transfer this ability to other projects. I can add multiple abilities,.
I can add other abilities
to engage with this ability, thus encapsulating the logic separately.
all it took was 1 line of code.
some of you may see it is the same principle as the matrix learn scene. or even the anime edgerunners.
what do you think?