this skill blinks the Arduino Led #13 based on commands comming from
the laptop(when you say blink, the Arduino/Elegoo Led blinks).
the merit of the skill is in showing how to condition Arduino code to run based on commands comming
from the laptop, more specifically, a livingrimoire skill outside the Arduino.
there are 2 parts to adding the skill:
1. adding the skill to the Arduino
in the Arduino IDE:
tools: select board and port connecting to the Arduino/elegoo
Sketch->Include Library->Add .ZIP Library...
select the LivinGrimoireLight290724.zip
LivinGrimoireLight_link
add the temperature skill files:
DiBlinker.h
add: DiBlinker.cpp
main Arduino code:
2. adding the skill to the laptop (PyCharm IDE)
(terminal) pip install pyserial
#######################################################
adding the DLC_Arduino_skills from the python directory:
file name: DLC_Arduino_skills.py
Arduino_skills_DLC_link
location: LivinGrimoire python/Python files/protoco; 2501/Arduino DLCs
in the main PyCharm IDE file add this function(Python code):
this will add skills via .py files with DLC in their file name.
note the above walkthrough includes some initial setup for elaboration.
this means adding additional skills is even shorter:
adding the livingrimoirelight library, adding the code in the python main program file
just add the skill files, and 1 code line per skill on the Arduino/Elegoo main code file.
the laptop(when you say blink, the Arduino/Elegoo Led blinks).
the merit of the skill is in showing how to condition Arduino code to run based on commands comming
from the laptop, more specifically, a livingrimoire skill outside the Arduino.
there are 2 parts to adding the skill:
1. adding the skill to the Arduino
in the Arduino IDE:
tools: select board and port connecting to the Arduino/elegoo
Sketch->Include Library->Add .ZIP Library...
select the LivinGrimoireLight290724.zip
LivinGrimoireLight_link
add the temperature skill files:
DiBlinker.h
Code:
#ifndef DiBlinker_H
#define DiBlinker_H
// using Arduino hardware codes outside main:
#include <Arduino.h>
#include "LivinGrimoireLight.h"
#include "DiHelloWorld.h"
// example hello world by blinking default Led #13 once
class DiBlinker : public Skill {
private:
Led _l1;
public:
DiBlinker(Led l1);
virtual void inOut(byte ear, byte skin, byte eye);
};
#endif
add: DiBlinker.cpp
Code:
#include <Arduino.h>
#include "DiBlinker.h"
#include "LivinGrimoireLight.h"
#include "DiHelloWorld.h"
DiBlinker::DiBlinker(Led l1)
{
Serial.begin(9600);
_l1 = l1;_l1.init();
}
void DiBlinker::inOut(byte ear, byte skin, byte eye)
{
// Check if data is available to read
if (Serial.available() > 0) {
// Read the incoming byte
char data = Serial.read();
// Blink the LED if the received data is '1'
if (data == '1') {
// turn the LED on (HIGH is the voltage level)
_l1.on();
delay(1000); // Wait for 1000 millisecond(s)
// turn the LED off by making the voltage LOW
_l1.off();
delay(1000); // Wait for 1000 millisecond(s)
}
}
}
main Arduino code:
Code:
#include "DiBlinker.h"
#include "LivinGrimoireLight.h"
Chobit* c1 = new Chobit();
void setup() {
Led led1(13); // used to initialize the Hello World skill
Skill* s2 = new DiBlinker(led1); // example skill created
c1->addSkill(s2);
}
void loop() {
c1->think(0, 0, 0);
}
2. adding the skill to the laptop (PyCharm IDE)
(terminal) pip install pyserial
#######################################################
adding the DLC_Arduino_skills from the python directory:
file name: DLC_Arduino_skills.py
Arduino_skills_DLC_link
location: LivinGrimoire python/Python files/protoco; 2501/Arduino DLCs
in the main PyCharm IDE file add this function(Python code):
Code:
import os
# noinspection PyUnusedLocal
def call_add_DLC_skills(brain: Brain):
for file in os.listdir('.'):
if file.endswith('.py') and 'DLC' in file:
module_name = file[:-3]
exec(f"import {module_name}")
exec(f"{module_name}.add_DLC_skills(brain)")
in the running code area add:
call_add_DLC_skills(brain)
this will add skills via .py files with DLC in their file name.
note the above walkthrough includes some initial setup for elaboration.
this means adding additional skills is even shorter:
adding the livingrimoirelight library, adding the code in the python main program file
just add the skill files, and 1 code line per skill on the Arduino/Elegoo main code file.