class Chobits:
def __init__(self):
super().__init__()
self._dClasses: list[DiSkillV2] = [] # _ is a private access modifier
def addSkill(self, skill: DiSkillV2) -> Chobits:
# add a skill (builder design patterned func))
self._dClasses.append(skill)
return self
def clearSkills(self):
# remove all skills
self._dClasses.clear()
def addSkills(self, *skills: DiSkillV2):
for skill in skills:
skill.setKokoro(self._kokoro)
self._dClasses.append(skill)
def think(self, ear: str, skin: str, eye: str) -> str:
for dCls in self._dClasses:
self.inOut(dCls, ear, skin, eye)
class List {
public:
byte length;
byte data[16];
void append(byte item) {
if (length < 16) data[length++] = item;
}
void remove(byte index) {
if (index >= length) return;
memmove(&data[index], &data[index+1], length -
index - 1);
length--;
}
};
List l { .length = 3, .data = { 12, 82, 29 } };
l.remove(1);
#define LED_PIN 13
// import the C++ file with the example Led class:
class Led{
private:
byte pin;
public:
Led(){this->pin = 13;}
Led(byte pin){
this->pin = pin;
}
void init(){
pinMode(pin, OUTPUT);
}
void on(){
digitalWrite(pin, HIGH);
}
void off(){
digitalWrite(pin, LOW);
}
};
class Skill{
private:
Led _l1;
public:
Skill(Led l1){_l1 = l1;_l1.init();}
void inOut(byte ear, byte skin, byte eye)
{
// 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)
}
};
Led led1(LED_PIN);
Skill s1(led1);
void setup()
{
led1.init();
}
void loop()
{
s1.inOut(1, 2, 3);
}
#define LED_PIN 13
// import the C++ file with the example Led class:
class Led{
private:
byte pin;
public:
Led(){this->pin = 13;}
Led(byte pin){
this->pin = pin;
}
void init(){
pinMode(pin, OUTPUT);
}
void on(){
digitalWrite(pin, HIGH);
}
void off(){
digitalWrite(pin, LOW);
}
};
class Skill{
virtual void inOut(byte ear, byte skin, byte eye) = 0;
};
class DiHelloWorld: Skill{
private:
Led _l1;
public:
DiHelloWorld(Led l1){_l1 = l1;_l1.init();}
void inOut(byte ear, byte skin, byte eye)
{
// 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)
}
};
Led led1(LED_PIN);
DiHelloWorld s1(led1);
void setup()
{
led1.init();
}
void loop()
{
s1.inOut(1, 2, 3);
}
// C++ code
//
class List {
public:
byte length;
byte data[16];
void append(byte item) {
if (length < 16) data[length++] = item;
}
void remove(byte index) {
if (index >= length) return;
memmove(&data[index], &data[index+1], length -
index - 1);
length--;
}
};
List l { .length = 3, .data = { 12, 82, 29 } };
void setup()
{
l.remove(1);
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
if (l.data[0] == 12){
digitalWrite(LED_BUILTIN, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(LED_BUILTIN, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
}
class Led{
private:
byte pin;
public:
Led(){this->pin = 13;}
Led(byte pin){
this->pin = pin;
}
void init(){
pinMode(pin, OUTPUT);
}
void on(){
digitalWrite(pin, HIGH);
}
void off(){
digitalWrite(pin, LOW);
}
};
class Skill {
public:
virtual void inOut() { Serial.println("A"); }
};
class DiHelloWorld : public Skill {
private:
Led _l1;
public:
DiHelloWorld(Led l1){_l1 = l1;_l1.init();}
virtual void inOut() {
// 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)
}
};
void setup() {
// Skill* obj; // base-class pointer
Skill* s1 = new Skill();
s1->inOut (); // base class version
Led led1(13);
Skill* s2 = new DiHelloWorld(led1);
s2->inOut ();
}
void loop() {
}
class Led{
private:
byte pin;
public:
Led(){this->pin = 13;}
Led(byte pin){
this->pin = pin;
}
void init(){
pinMode(pin, OUTPUT);
}
void on(){
digitalWrite(pin, HIGH);
}
void off(){
digitalWrite(pin, LOW);
}
};
class Skill {
public:
virtual void inOut() { Serial.println("A"); }
};
class DiHelloWorld : public Skill {
private:
Led _l1;
public:
DiHelloWorld(Led l1){_l1 = l1;_l1.init();}
virtual void inOut() {
// 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)
}
};
// list of skills
class List {
public:
byte length;
Skill* data[16];
void append(Skill* item) {
if (length < 16) data[length++] = item;
}
void remove(byte index) {
if (index >= length) return;
memmove(&data[index], &data[index+1], length -
index - 1);
length--;
}
};
void setup() {
// Skill* obj; // base-class pointer
Skill* s1 = new Skill();
s1->inOut (); // base class version
Led led1(13);
Skill* s2 = new DiHelloWorld(led1);
s2->inOut ();
}
void loop() {
}
class Led{
private:
byte pin;
public:
Led(){this->pin = 13;}
Led(byte pin){
this->pin = pin;
}
void init(){
pinMode(pin, OUTPUT);
}
void on(){
digitalWrite(pin, HIGH);
}
void off(){
digitalWrite(pin, LOW);
}
};
class Skill {
public:
virtual void inOut() { Serial.println("A"); }
};
class DiHelloWorld : public Skill {
private:
Led _l1;
public:
DiHelloWorld(Led l1){_l1 = l1;_l1.init();}
virtual void inOut() {
// 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)
}
};
// list of skills
class ListOfSkills {
public:
byte length = 0;
Skill* data[16];
void append(Skill* item) {
if (length < 16) data[length++] = item;
}
void remove(byte index) {
if (index >= length) return;
memmove(&data[index], &data[index+1], length -
index - 1);
length--;
}
};
// Chobit
class Chobit
{
private:
ListOfSkills* dSkills = new ListOfSkills();
public:
void addSkill(Skill* s1)
{
dSkills->append(s1);
}
void clearSkills()
{
dSkills = new ListOfSkills();
}
void think(byte ear, byte skin, byte eye)
{
for(int i=0;i<dSkills->length;i++)
{
dSkills->data[i]->inOut();
}
}
};
void setup() {
// Skill* obj; // base-class pointer
// Skill* s1 = new Skill();
// s1->inOut (); // base class version
Led led1(13);
Skill* s2 = new DiHelloWorld(led1);
// s2->inOut ();
Chobit* c1 = new Chobit();
c1->addSkill(s2);
c1->think(0, 0, 0);
}
void loop() {
}
// example Led class
class Led{
private:
byte pin;
public:
// c'tor
Led(){this->pin = 13;}
// c'tor with param
Led(byte pin){
this->pin = pin;
}
// cls methods
void init(){
pinMode(pin, OUTPUT);
}
void on(){
digitalWrite(pin, HIGH);
}
void off(){
digitalWrite(pin, LOW);
}
};
// Skill super class
class Skill {
public:
Skill(){}
virtual void inOut()
{
// override me
}
};
// example hello world by blinking default Led #13 once
class DiHelloWorld : public Skill {
private:
Led _l1;
public:
DiHelloWorld(Led l1){_l1 = l1;_l1.init();}
virtual void inOut() {
// 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)
}
};
// list of Skill objects
// only the Chobit cls uses it
class ListOfSkills {
public:
byte length = 0;
Skill* data[16];
void append(Skill* item) {
if (length < 16) data[length++] = item;
}
void remove(byte index) {
if (index >= length) return;
memmove(&data[index], &data[index+1], length -
index - 1);
length--;
}
};
// Chobit
class Chobit
{
private:
ListOfSkills* dSkills = new ListOfSkills();
public:
void addSkill(Skill* s1)
{
dSkills->append(s1);
}
void clearSkills()
{
dSkills = new ListOfSkills();
}
// run all added skills
void think(byte ear, byte skin, byte eye)
{
for(int i=0;i<dSkills->length;i++)
{
dSkills->data[i]->inOut();
}
}
};
void setup() {
Led led1(13); // used to initialize the Hello World skill
Skill* s2 = new DiHelloWorld(led1); // example skill created
Chobit* c1 = new Chobit();
c1->addSkill(s2);
c1->think(0, 0, 0);
c1->think(0, 0, 0);
}
void loop() {
}
#ifndef LivinGrimoireLight_H
#define LivinGrimoireLight_H
#include <Arduino.h>
// Skill super class
class Skill {
public:
Skill(){}
virtual void inOut()
{
// override me
}
};
// list of Skill objects
// only the Chobit cls uses it
class ListOfSkills {
public:
byte length = 0;
Skill* data[16];
void append(Skill* item) {
if (length < 16) data[length++] = item;
}
void remove(byte index) {
if (index >= length) return;
memmove(&data[index], &data[index+1], length -
index - 1);
length--;
}
};
// Chobit
class Chobit
{
private:
ListOfSkills* dSkills = new ListOfSkills();
public:
void addSkill(Skill* s1)
{
dSkills->append(s1);
}
void clearSkills()
{
dSkills = new ListOfSkills();
}
// run all added skills
void think(byte ear, byte skin, byte eye)
{
for(int i=0;i<dSkills->length;i++)
{
dSkills->data[i]->inOut();
}
}
};
#endif
#ifndef DiHelloWorld_H
#define DiHelloWorld_H
// using Arduino hardware codes outside main:
#include <Arduino.h>
#include "LivinGrimoireLight.h"
class Led{
private:
byte pin;
public:
Led(){this->pin = 13;}
Led(byte pin){
this->pin = pin;
}
void init(){
pinMode(pin, OUTPUT);
}
void on(){
digitalWrite(pin, HIGH);
}
void off(){
digitalWrite(pin, LOW);
}
};
// example hello world by blinking default Led #13 once
class DiHelloWorld : public Skill {
private:
Led _l1;
public:
DiHelloWorld(Led l1){_l1 = l1;_l1.init();}
virtual void inOut() {
// 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)
}
};
#endif
#include "DiHelloWorld.h"
#include "LivinGrimoireLight.h"
void setup() {
Led led1(13); // used to initialize the Hello World skill
Skill* s2 = new DiHelloWorld(led1); // example skill created
Chobit* c1 = new Chobit();
c1->addSkill(s2);
c1->think(0, 0, 0);
c1->think(0, 0, 0);
}
void loop() {
}