/* Edge Impulse ingestion SDK
* Copyright (c) 2022 EdgeImpulse Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
// If your target is limited in memory remove this macro to save 10K RAM
#define EIDSP_QUANTIZE_FILTERBANK 0
/**
* Define the number of slices per model window. E.g. a model window of 1000 ms
* with slices per model window set to 4. Results in a slice size of 250 ms.
* For more info: https://docs.edgeimpulse.com/docs/continuous-audio-sampling
*/
#define EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW 1
/*
** NOTE: If you run into TFLite arena allocation issue.
**
** This may be due to may dynamic memory fragmentation.
** Try defining "-DEI_CLASSIFIER_ALLOCATION_STATIC" in boards.local.txt (create
** if it doesn't exist) and copy this file to
** `<ARDUINO_CORE_INSTALL_PATH>/arduino/hardware/<mbed_core>/<core_version>/`.
**
** See
** (https://support.arduino.cc/hc/en-us/articles/360012076960-Where-are-the-installed-cores-located-)
** to find where Arduino installs cores on your machine.
**
** If the problem persists then there's not enough memory for this model and application.
*/
/* Includes ---------------------------------------------------------------- */
#include <PDM.h>
#include <RME_Investigation_II_inferencing.h>
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7789.h> // Hardware-specific library for ST7789
#include <SPI.h>
// for image
#include <Adafruit_BusIO_Register.h>
#include <Adafruit_I2CDevice.h>
#include <Adafruit_I2CRegister.h>
#include <Adafruit_SPIDevice.h>
#include <SdFat.h> // SD card & FAT filesystem library
#include <Adafruit_SPIFlash.h> // SPI / QSPI flash library
#include <Adafruit_ImageReader.h> // Image-reading functions
// continuous
/** Audio buffers, pointers and selectors */
typedef struct {
signed short *buffers[2];
unsigned char buf_select;
unsigned char buf_ready;
unsigned int buf_count;
unsigned int n_samples;
} inference_t;
static inference_t inference;
static bool record_ready = false;
static signed short *sampleBuffer;
static bool debug_nn = false; // Set this to true to see e.g. features generated from the raw signal
static int print_results = -(EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW);
// end here
static int res[6];
static int counter = 0;
static char *text = "Please keep tossing, coins give me insight!";
static char *image = "";
// screen controller: for text
#define TFT_CS D10
#define TFT_RST -1 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC D8
//may cause bug here
#define TFT_COPI D11 // Data out
#define TFT_SCLK D13 // Clock out
// screen controller: for image
#define USE_SD_CARD
#define SD_CS 4 // SD card select pin
//may cause bug here
Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
float p = 3.1415926;
// end here
#if defined(USE_SD_CARD)
SdFat SD; // SD card filesystem
Adafruit_ImageReader reader(SD); // Image-reader object, pass in SD filesys
#else
// SPI or QSPI flash filesystem (i.e. CIRCUITPY drive)
#if defined(__SAMD51__) || defined(NRF52840_XXAA)
Adafruit_FlashTransport_QSPI flashTransport(PIN_QSPI_SCK, PIN_QSPI_CS,
PIN_QSPI_IO0, PIN_QSPI_IO1, PIN_QSPI_IO2, PIN_QSPI_IO3);
#else
#if (SPI_INTERFACES_COUNT == 1)
Adafruit_FlashTransport_SPI flashTransport(SS, &SPI);
#else
Adafruit_FlashTransport_SPI flashTransport(SS1, &SPI1);
#endif
#endif
Adafruit_SPIFlash flash(&flashTransport);
FatFileSystem filesys;
Adafruit_ImageReader reader(filesys); // Image-reader, pass in flash filesys
#endif
ImageReturnCode status; // Status from image-reading functions
Adafruit_Image img; // An image loaded into RAM
int32_t width = 0, // BMP image dimensions
height = 0;
//end here
/**
* @brief Arduino setup function
*/
void setup() {
// tft.clear();
// put your setup code here, to run once:
Serial.begin(115200);
// comment out the below line to cancel the wait for USB connection (needed for native USB)
while (!Serial)
;
Serial.println("Edge Impulse Inferencing Demo");
// summary of inferencing settings (from model_metadata.h)
ei_printf("Inferencing settings:\n");
ei_printf("\tInterval: %.2f ms.\n", (float)EI_CLASSIFIER_INTERVAL_MS);
ei_printf("\tFrame size: %d\n", EI_CLASSIFIER_DSP_INPUT_FRAME_SIZE);
ei_printf("\tSample length: %d ms.\n", EI_CLASSIFIER_RAW_SAMPLE_COUNT / 16);
ei_printf("\tNo. of classes: %d\n", sizeof(ei_classifier_inferencing_categories) / sizeof(ei_classifier_inferencing_categories[0]));
if (microphone_inference_start(EI_CLASSIFIER_RAW_SAMPLE_COUNT) == false) {
ei_printf("ERR: Could not allocate audio buffer (size %d), this could be due to the window length of your model\r\n", EI_CLASSIFIER_RAW_SAMPLE_COUNT);
return;
}
// for screen
//SPI.begin(); // init SPI
Serial.print(F("Hello! ST77xx TFT Test"));
// OR use this initializer (uncomment) if using a 1.47" 172x320 TFT:
tft.init(172, 320); // Init ST7789 172x320
// SPI speed defaults to SPI_DEFAULT_FREQ defined in the library, you can override it here
// Note that speed allowable depends on chip and quality of wiring, if you go too fast, you
// may end up with a black screen some times, or all the time.
tft.setSPISpeed(32000000);
//tft.setSPIFreqency(1000000); // set 1 MHz
//tft.initR(); // init @ 1 MHz.
Serial.println(F("Initialized"));
tft.fillScreen(ST77XX_BLACK);
uint16_t time = millis();
time = millis() - time;
Serial.println(time, DEC);
delay(500);
// for image
Serial.print(F("Initializing filesystem..."));
#if defined(USE_SD_CARD)
// SD card is pretty straightforward, a single call...
if (!SD.begin(SD_CS, SD_SCK_MHZ(10))) { // Breakouts require 10 MHz limit due to longer wires
Serial.println(F("SD begin() failed"));
for (;;)
; // Fatal error, do not continue
}
#else
// SPI or QSPI flash requires two steps, one to access the bare flash
// memory itself, then the second to access the filesystem within...
if (!flash.begin()) {
Serial.println(F("flash begin() failed"));
for (;;)
;
}
if (!filesys.begin(&flash)) {
Serial.println(F("filesys begin() failed"));
for (;;)
;
}
#endif
for (int i = 0; i < 6; i++) {
res[i] = -1;
}
}
/**
* @brief Arduino main function. Runs the inferencing loop.
*/
void loop() {
bool m = microphone_inference_record();
if (!m) {
ei_printf("ERR: Failed to record audio...\n");
return;
}
signal_t signal;
signal.total_length = EI_CLASSIFIER_RAW_SAMPLE_COUNT;
signal.get_data = µphone_audio_signal_get_data;
ei_impulse_result_t result = { 0 };
EI_IMPULSE_ERROR r = run_classifier(&signal, &result, debug_nn);
if (r != EI_IMPULSE_OK) {
ei_printf("ERR: Failed to run classifier (%d)\n", r);
return;
}
if (++print_results >= (EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW)) {
// print the predictions
ei_printf("Predictions ");
ei_printf("(DSP: %d ms., Classification: %d ms., Anomaly: %d ms.)",
result.timing.dsp, result.timing.classification, result.timing.anomaly);
ei_printf(": \n");
for (size_t ix = 0; ix < EI_CLASSIFIER_LABEL_COUNT; ix++) {
ei_printf(" %s: %.5f\n", result.classification[ix].label,
result.classification[ix].value);
if (result.classification[ix].value > 0.8 && counter < 6) {
if (get_enum(result.classification[ix].label) != -1) {
res[counter] = get_enum(result.classification[ix].label);
counter++;
}
}
// ei_printf("counter:%d\n", counter);
if (counter == 6) {
ei_printf("1.%d, 2.%d, 3.%d, 4.%d, 5.%d, 6.%d\n", res[0], res[1], res[2], res[3], res[4], res[5]);
// no zero 1
if (res[0] == 1 && res[1] == 1 && res[2] == 1 && res[3] == 1 && res[4] == 1 && res[5] == 1) {
text = "There may be creative potential in your situation that you cannot yet perceive, or perhaps you are not being recognized. Hold your power in reserve if the timing is not yet right for action. Trying to make a lot of progress too early is like trying to cook noodles in cold water—you must wait until the water boils. Harbor no fears about your ability to be successful. Be confident. Your time is coming.";
image = "/111111.bmp";
ei_printf(text);
}
// 1 zero 6
if (res[0] == 0 && res[1] == 1 && res[2] == 1 && res[3] == 1 && res[4] == 1 && res[5] == 1) {
text = "There may be creative potential in your situation that you cannot yet perceive, or perhaps you are not being recognized. Hold your power in reserve if the timing is not yet right for action. Trying to make a lot of progress too early is like trying to cook noodles in cold water—you must wait until the water boils. Harbor no fears about your ability to be successful. Be confident. Your time is coming.";
image = "/011111.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 1 && res[3] == 1 && res[4] == 1 && res[5] == 1) {
text = "In its first stage, success is innocent and blameless. It has not yet faced the challenges that accomplishment brings. Avoid creating future harm by guarding against self-indulgence; show consideration by exercising skillful restraint. Speak of personal or business matters only with trusted advisors; to all others, stay relaxed and detached. Leave your ego at the door—there is no space for arrogance. Acting thus will strengthen others' perception of you as a person endowed with confidence as well as wealth.";
image = "/101111.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 0 && res[3] == 1 && res[4] == 1 && res[5] == 1) {
text = "When a strong person encounters an obstacle in his or her path, the first inclination is to press forward, to remove it, or to overcome it by force. In the present circumstances, however, do not let yourself be drawn into direct action or conflict. Instead, stand back and take some time to assess the situation; consider all your options. Give yourself the space to advance or retreat—or to do nothing at all—for the time being.";
image = "/110111.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 1 && res[3] == 0 && res[4] == 1 && res[5] == 1) {
text = "When coming from a humble position, inner strength in the form of modesty is a key to advancement. Conscientious work is rewarded when one's motives are simple and intentions genuine (especially when credit goes to the supervisor). Simplicity in action will leave you free of obligation. To strive aggressively now could put you in a position of greater difficulty.";
image = "/111011.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 1 && res[3] == 1 && res[4] == 0 && res[5] == 1) {
text = "When guests gather at the door, enthusiasm is high, and divergent agendas are not yet apparent—such are the beginnings of fellowship. Use these moments carefully; they are opportunities not to be missed. To foster goodwill among a group at the start of an enterprise or consortium, avoid secret agreements. Goodwill is a fruit that blossoms in the light of transparency.";
image = "/111101.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 1 && res[3] == 1 && res[4] == 1 && res[5] == 0) {
text = "As soon as it becomes clear that an unseemly element has crashed the party, show that distraction to the door. In social situations, one careless person can disrupt the lives of many good people; and such a person may also have many derelict relations. The intrusion of self-serving forces may also indicate a small, unhealthy craving—one that, if not checked in time, can become a destructive obsession.";
image = "/111110.bmp";
ei_printf(text);
}
//2 zero 15 -here
if (res[0] == 0 && res[1] == 0 && res[2] == 1 && res[3] == 1 && res[4] == 1 && res[5] == 1) {
text = "Possessing great vigor does not assure success all by itself. If you start your movement from a lowly or weak position, attempting to advance prematurely or too quickly through forceful efforts will bring misfortune. Even for those of great strength and ability, progress must be achieved step by step.";
image = "/001111.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 0 && res[3] == 1 && res[4] == 1 && res[5] == 1) {
text = "Troubling events may be looming, causing some apprehension. Avoid reacting prematurely; just keep your life in order. Do not try to alter the path that has been set for you at this time. Rest assured that you are heading in the right direction; do not become impatient or greedy. Even though a challenge may be looming, the skillful response is to make preparations, gaining strength for future battles. Let go of anxious thinking. Meditate. Remain open, alert, and prepared.";
image = "/010111.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 1 && res[3] == 0 && res[4] == 1 && res[5] == 1) {
text = "Living a life of quiet, self-contained joy is the height of good fortune. Eat when you are hungry, “work” doing what you love, sleep when you are tired, take your pleasures when you will—what could be better?";
image = "/011011.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 1 && res[3] == 1 && res[4] == 0 && res[5] == 1) {
text = "At the beginning of a period of big changes, there is no need to hurry. You can restrain yourself a little bit, for this line indicates that the timing is not yet perfectly ripe. Events are just starting to take shape, and we cannot know precisely what form will solidify in the end. In great revolutions, the first wave of leaders is usually killed; it is the second wave that endures. Premature action can lead to misfortune.";
image = "/011101.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 1 && res[3] == 1 && res[4] == 1 && res[5] == 0) {
text = "When embarking on an ambitious undertaking during turbulent times, the wise take great care, especially in the beginning. Proper planning and the laying of a good foundation are too often neglected in the excitement of the moment. Such carelessness is bound to cause problems later. Attending to careful preparation now will leave you in a much better position in the future.";
image = "/011110.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 0 && res[3] == 1 && res[4] == 1 && res[5] == 1) {
text = "A changing line in the first position indicates restraining an impulse to act at this time. You may wish to make strong advances, but there seems to be an obstacle in your way. Compose yourself and wait for a better time to vent your pent-up energy. In the meantime, keeping still will help to increase your power.";
image = "/100111.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 1 && res[3] == 0 && res[4] == 1 && res[5] == 1) {
text = "Trying to rectify estrangements caused by small misunderstandings can lead to situations similar to that of a person whose horse has escaped the barn. Dashing after the horse in a futile effort to capture it makes the horse run faster and farther away. But if the person simply returns home, the matter is settled quite easily, for the horse will return to the barn once it becomes hungry or thirsty.";
image = "/101011.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 1 && res[3] == 1 && res[4] == 0 && res[5] == 1) {
text = "When awakening to a new day, some concentration is necessary, so that your central tasks are not obscured by frenzied activity. It is at the beginning that one needs to compose oneself. As seeds are planted, so shall they grow. Do not begin a new project without careful consideration.";
image = "/101101.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 1 && res[3] == 1 && res[4] == 1 && res[5] == 0) {
text = "If you are virtuous as you nurture your unique talents, you will succeed—even if you are in a humble position at the moment. Cleanse yourself of unbecoming traits such as pride or excessive concerns about money, and be open-minded to other people even when their worst traits are showing—they may have something to teach you. If sadness or grief has been a part of your life recently, use the depth of emotion underneath the situation to nourish your soul and clarify your vision.";
image = "/101110.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 0 && res[3] == 0 && res[4] == 1 && res[5] == 1) {
text = "Inner preparation brings success. Personal stability of character and a steadfast dedication to the truth that underlies every situation inevitably leads to good fortune. Relying on the perceptions of others is not possible in this context; you must learn to stand on your own, learn to be self-reliant, and learn to apply the power of knowing to make the right moves at the right time.";
image = "/110011.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 0 && res[3] == 1 && res[4] == 0 && res[5] == 1) {
text = "Every group needs some guidelines in order to succeed. When beginning any activity or project that requires the exercise of authority, it is vital to exercise power firmly and evenly. This may cause problems in the beginning, but it is the only way to create a stable situation that can produce positive results. If kindness remains an element of authority, dissatisfaction ultimately vanishes as things start to go well. Leading and training others requires that you embody both integrity and consistency.";
image = "/110101.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 0 && res[3] == 1 && res[4] == 1 && res[5] == 0) {
text = "Excessive reliance on tradition may have produced some corruption, but in this case, it is not yet deeply rooted. Repair can be achieved without too much effort, even though some danger is present. Remain alert to the risks inherent in change and you will be able to avoid possible damage. Repair in itself is not a panacea, however. Restorative efforts must be watched carefully, particularly in the early stages, to see that the previous rot is not contaminating them as well.";
image = "/110110.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 1 && res[3] == 0 && res[4] == 0 && res[5] == 1) {
text = "The first impulses of the heart are usually pure and good. It is safe to follow them confidently—provided that your actions are harmless to yourself or others. When you reach an impasse in tangled affairs, it is helpful to review the original impulse or purpose for that course of action. Good fortune awaits one who protects their innocence.";
image = "/111001.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 1 && res[3] == 0 && res[4] == 1 && res[5] == 0) {
text = "Disputes and a dangerously charged atmosphere seem likely, but the storm will blow over if you remain careful. Do not force things; avoid fighting. There still may be a simple solution at hand since it is possible that a minor misunderstanding is at the root of the present conflict. If you face an adversary who is much stronger than you, drop the dispute quickly. If you are engaging an equal, seek allies.";
image = "/111010.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 1 && res[3] == 1 && res[4] == 0 && res[5] == 0) {
text = "In retreat, positioning is vitally important. Avoid being too visible—too close to the source of your opposition. If you do find yourself positioned in an opponent's sights, the best tactic may be to keep still, lie low, and wait for the moment to pass. Be extremely careful, because any movement now could work to your opposition's advantage.";
image = "/111100.bmp";
ei_printf(text);
}
// 3 zero 20 -here
if (res[0] == 0 && res[1] == 0 && res[2] == 0 && res[3] == 1 && res[4] == 1 && res[5] == 1) {
text = "In times of peace and prosperity, an individual of high purpose is able to draw like-minded people to a good cause. As such people become available, enlist their support. Now is the time for people of talent to set out to accomplish something.";
image = "/000111.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 1 && res[3] == 0 && res[4] == 1 && res[5] == 1) {
text = "This can be a time of accomplishment, even if you find yourself with less status than you desired or with more limited resources than you wish you had. If you accept your position and destiny, you may discover new secrets close to home and even come to feel happy in these circumstances. Being in the proximity of power is something to be appreciated in itself. This might be a time to undertake something, because good fortune is riding with you.";
image = "/001011.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 1 && res[3] == 1 && res[4] == 0 && res[5] == 1) {
text = "To facilitate an experience of abundance, bring a mixture of energy and vision. This combination often comes from two people who are joining together in an effort, project, or relationship. Indications are that they're well matched and their partnership is well founded. This line indicates that the timing is good for a partnership that can help you advance to the top. Good fortune awaits you.";
image = "/001101.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 1 && res[3] == 1 && res[4] == 1 && res[5] == 0) {
text = "Trying to establish an enduring relationship too quickly can easily bring misfortune. It is much better to practice patience than to expect immediate success. Let things develop more slowly, step by step. What endures best is that which has been carefully cultivated. If you are craving too much too quickly, you may end up with nothing.";
image = "/001110.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 0 && res[3] == 0 && res[4] == 1 && res[5] == 1) {
text = "Before initiating any significant action, a wise person first evaluates their ability to successfully carry out the task. If the limitations are overwhelming, no action will be taken. But inaction is a decision and an action of sorts, because the passage of time itself can bring strength to what has been weak and energy to what has been still. Maintain a steady purpose, but act only when you can feel that the time is ripe. In this way, limitations serve your best interests. With discretion and good timing, anything can be carried through to resolution.";
image = "/010011.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 0 && res[3] == 1 && res[4] == 0 && res[5] == 1) {
text = "In the period following the completion of a major undertaking, the momentum of previous effort still exists; and there is a tendency to continue onward. But be careful; for once a project has reached its proper end point, continuation for its own sake can bring misfortune. Pressing ahead after completion can threaten to bring collapse to established success. Even so, no real harm results if your approach and demeanor have been correct.";
image = "/010101.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 0 && res[3] == 1 && res[4] == 1 && res[5] == 0) {
text = "Drinking from a muddy well leads to misfortune. The mind easily becomes confused when it is preoccupied with trivialities or phantom images. Plumb the source. Live your life fully and plunge in deeply—but don’t dive in too far or over your head too quickly. Foolhardy endeavors are a waste of time.";
image = "/010110.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 1 && res[3] == 0 && res[4] == 0 && res[5] == 1) {
text = "When a person of vision undertakes a challenge, he or she must sometimes change direction in the course of events. When these changes result from sincere communication with those of different opinions, good fortune will follow. But care must be taken not to be swayed by current opinion. Carry your convictions out into the crowd. Stay open to the ideas of others, but hold your ground on matters of integrity.";
image = "/011001.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 1 && res[3] == 0 && res[4] == 1 && res[5] == 0) {
text = "No matter how overwhelming the challenges might seem, an attitude of gloom or melancholy only makes them feel worse. By working to overcome problems inwardly and committing to move forward without despair, progress is still possible. Banish the phantoms of self-pity before moving to slay the dragons of misfortune.";
image = "/011010.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 1 && res[3] == 1 && res[4] == 0 && res[5] == 0) {
text = "In the safety of one's bed, one wiggles one's toes. Does this mean this person is about to undertake a long journey? No one knows. The situation is of little importance.";
image = "/011100.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 0 && res[3] == 0 && res[4] == 1 && res[5] == 1) {
text = "If you want to be of service to others who have less, there is no blame in that. But you must be careful to not assume too much responsibility for them, lest you deprive them of their dignity and the chance to advance through their own effort. Learn to be sensitive when taking on the burdens of others, and carefully avoid self-righteousness. Likewise, when the tables are turned, a mature person considers how much help he or she can accept without putting their helpers at risk. Such deep consideration makes giving and receiving happen with ease over time, and without concern about possible decrease.";
image = "/100011.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 0 && res[3] == 1 && res[4] == 0 && res[5] == 1) {
text = "Resist the temptation to create false impressions of your position or stature. It is more graceful and dignified to wash your own car for picking up an honored guest than to rent a limousine.";
image = "/100101.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 0 && res[3] == 1 && res[4] == 1 && res[5] == 0) {
text = "Excessive reliance on tradition may have produced some corruption, but in this case, it is not yet deeply rooted. Repair can be achieved without too much effort, even though some danger is present. Remain alert to the risks inherent in change and you will be able to avoid possible damage. Repair in itself is not a panacea, however. Restorative efforts must be watched carefully, particularly in the early stages, to see that the previous rot is not contaminating them as well.";
image = "/100110.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 1 && res[3] == 0 && res[4] == 0 && res[5] == 1) {
text = "A first offense is not cause for condemnation and stiff punishment, but some form of corrective action may be needed in order to prevent further transgressions. If you have been wronged, confront the matter openly but without hostility.";
image = "/101001.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 1 && res[3] == 0 && res[4] == 1 && res[5] == 0) {
text = "In periods of chaos, there is a natural tendency to become anxious, throw caution to the wind, and rush ahead. Like the young fox that dashes across a frozen lake, it will be treading on thin ice if an attempt is made to escape problems too quickly. Hold back a little to spare yourself from such dangers.";
image = "/101010.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 1 && res[3] == 1 && res[4] == 0 && res[5] == 0) {
text = "When you are in a vulnerable position—as is any wanderer—do not become involved with trivial matters that are not your concern. Maintain your sense of purpose, and don’t allow yourself to be distracted. If forced into tempting circumstances, maintain your dignity and reserve; otherwise, misfortunes will happen. A traveler preoccupied with petty things is inviting bad luck. As ever, perseverance furthers.";
image = "/101100.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 0 && res[3] == 0 && res[4] == 0 && res[5] == 1) {
text = "When you are the recipient of what might be considered blind luck, realize that good fortune has found you because you allowed room for it to enter. Luck is most attracted to selflessness. When luck shows up—in the form of new wealth, power, or energy—it is best preserved and strengthened by sharing this increase with others, perhaps by donating time to worthwhile and selfless pursuits.";
image = "/110001.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 0 && res[3] == 0 && res[4] == 1 && res[5] == 0) {
text = "In all significant undertakings, it is critical that dissension be handled quickly. Misunderstandings and feuds that are allowed to linger and fester can rapidly develop into open wounds that affect an entire community or project. Conflicts caused by hidden factors need to be brought to light and dissolved as soon as possible, to avoid further arguments and wasted energy. Once this is done, good fortune awaits.";
image = "/110010.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 0 && res[3] == 1 && res[4] == 0 && res[5] == 0) {
text = "Visualize a lonely youth setting forth on his or her own to face a huge challenge. Their perception of the circumstances—the magnitude—makes them careful. When one is cautious and steadfast, one has good fortune. When situations are allowed to develop gradually, in due time, liabilities evolve into assets.";
image = "/110100.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 1 && res[2] == 1 && res[3] == 0 && res[4] == 0 && res[5] == 0) {
text = "Small-minded forces are advancing now, so it is best to reduce your visibility. Others of like mind may follow you into a temporary shelter from the conflict; it is through this means that plans can be made for future action.";
image = "/111000.bmp";
ei_printf(text);
}
// no one 1
if (res[0] == 0 && res[1] == 0 && res[2] == 0 && res[3] == 0 && res[4] == 0 && res[5] == 0) {
text = "Something in your current situation or a close relationship is foreboding, like the first frost of the autumn season that warns of the deadly cold of winter. Heed small warning signs that you may see at this time. Prepare yourself. Gather firewood now, and you will be prepared to fend off the fiercest cold. Watch for signs of decay.";
image = "/000000.bmp";
ei_printf(text);
}
// 1 one 6
if (res[0] == 1 && res[1] == 0 && res[2] == 0 && res[3] == 0 && res[4] == 0 && res[5] == 0) {
text = "Slander and intrigue abound. One image is of rats scurrying about, undermining the foundation of a house. At present, any movement at all can provide new fuel for inferior forces at work. Only by doing nothing can you hasten the end of this discomfort. Be patient—and brave.";
image = "/100000.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 0 && res[3] == 0 && res[4] == 0 && res[5] == 0) {
text = "Sincerity is the foundation of all successful relationships. In a thirsty world, it is not the form of the water's container that matters; it's the contents!";
image = "/010000.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 1 && res[3] == 0 && res[4] == 0 && res[5] == 0) {
text = "Self-consciously flaunting enthusiasm invites misfortune. Those around you need to ignite their own flames. Turning up the jets on your burners will not help if those around you are out of fuel. If others cannot keep up, you may need to slow the pace. If your associates have fuel but no fire, your selfless focus on the work at hand can be the flint that ignites their enthusiasm. A sense of unity can result.";
image = "/001000.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 0 && res[3] == 1 && res[4] == 0 && res[5] == 0) {
text = "Arrogant people create unnecessary complications for themselves when facing a major task. For one thing, concern about how they might be perceived or judged becomes an extra obstacle to the task’s completion. On the other hand, the unassuming attitude that goes along with humility supports the ability to have greater focus. While the conceited worry about appearances or the opinions of others, humble people concentrate on what needs to be done. Make no superior claims or conditions and you will meet no resistance.";
image = "/000100.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 0 && res[3] == 0 && res[4] == 1 && res[5] == 0) {
text = "At the beginning of any major movement, establishing good order is essential. Get your ducks in a row before you start quacking orders. Nothing good can be achieved without organizing your assets and coordinating your troops.";
image = "/000010.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 0 && res[3] == 0 && res[4] == 0 && res[5] == 1) {
text = "Everyone suffers setbacks from time to time. Some lucky people suffer small ones early in life and learn that they can survive a period of collapse. In this case, a minor setback is little more than an inconvenience but serves to build character, as long as proper action is taken before things decline too far. Persevere, always returning to the main road, as good fortune lies ahead.";
image = "/000001.bmp";
ei_printf(text);
}
//2 one 15 -here
if (res[0] == 1 && res[1] == 1 && res[2] == 0 && res[3] == 0 && res[4] == 0 && res[5] == 0) {
text = "When a novice practices contemplation, he or she is likely to miss the depth of the forces at work in the current environment—due to a lack of experience, wisdom, or good judgment. While such limitations are natural for beginners, with practice and lived experience, people know better than to be misled by the surface appearance of things; they do not overlook the connectivity of the whole. Do your best to look deeply. When in the presence of someone possessing a greater capacity for profound understanding, pay close attention. Even when you do not fully understand a wise person's advice, it can still help you.";
image = "/110000.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 1 && res[3] == 0 && res[4] == 0 && res[5] == 0) {
text = "Progress seems to be thwarted. If you lack confidence now, remain calm and accept that your influence may not be strong enough yet to achieve great progress. Though advancement may be fervently desired, the hour for you to play a leading role has not yet come. Do not feel downhearted or resentful if no one is paying a lot of attention to you. Remain calm and dedicated, and you will avoid serious mistakes that could halt your progress altogether.";
image = "/101000.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 0 && res[3] == 1 && res[4] == 0 && res[5] == 0) {
text = "At the beginning of a major undertaking, reserve energy by pausing for rest and reflection at the start. Taking a moment to chart your course before setting out on an adventure supports good timing and brings good fortune. This is the point in your undertaking when few mistakes have been made and innocence is untainted by ulterior motives. Persevere in staying balanced, and you will be able to establish a firm, lasting foundation.";
image = "/100100.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 0 && res[3] == 0 && res[4] == 1 && res[5] == 0) {
text = "Sustainable progress requires some degree of order. Training begins with discipline. It is the nature of youth to stumble into error through carelessness or playfulness; similar problems can plague childish adults too. While discipline is essential to achieve success, steer clear of boring routines or extreme regulations that choke creativity.";
image = "/100010.bmp";
ei_printf(text);
}
if (res[0] == 1 && res[1] == 0 && res[2] == 0 && res[3] == 0 && res[4] == 0 && res[5] == 1) {
text = "Envy is the dark underside of the rock of healthy ambition. A deeply felt covetousness, when fed by self-pity, always brings misfortune. To counter a tendency toward envy, practice self-reliance and take control of yourself.";
image = "/100001.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 1 && res[3] == 0 && res[4] == 0 && res[5] == 0) {
text = "Right now, a group needs to recognize its need for clear direction and strong leadership. Finding the right leader will bring good fortune. A suitable person who is a potential center of strength and purpose is already present. Such a gifted individual should be approached and asked to take a leadership position. As soon as this overture to the right person is made, general distress will disappear.";
image = "/011000.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 0 && res[3] == 1 && res[4] == 0 && res[5] == 0) {
text = "Your way ahead is blocked; the time is not right for direct action. Retreat, reflect on the situation, and wait for the right moment to overcome the obstacle. When confronted with a threatening roadblock, it is a mistake to forge ahead blindly. Look for an opening through or a detour around what is in your way. Also, wait for the right time to move.";
image = "/010100.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 0 && res[3] == 0 && res[4] == 1 && res[5] == 0) {
text = "Harm will come to those who make a habit of taking unnecessary risks without thinking. Like a performer who suddenly discovers—in the middle of an act—that there is no safety net below, the reality of one's risk-taking may sneak up on a person at the worst time, even though the dilemma has been obvious to everyone else. Caught in such a predicament, there is little to do but take care to avoid further recklessness, and focus on maintaining your balance as best you can.";
image = "/010010.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 1 && res[2] == 0 && res[3] == 0 && res[4] == 0 && res[5] == 1) {
text = "The way is blocked for now. Remain determined and act sensibly. Do not hesitate, but do not force things either. You have little power over the situation for the time being, but don’t give up. With a strong spirit and some humility, you will attract the people and knowledge you need soon enough. Seek the advice of someone more experienced than you.";
image = "/010001.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 1 && res[3] == 1 && res[4] == 0 && res[5] == 0) {
text = "A baby bird meets misfortune by trying to fly from the nest prematurely. The small must attain a certain stature before making even the most preliminary advance. A willingness to attempt difficult tasks too quickly invites unfortunate consequences. Stick to basics for the moment, and make security a priority.";
image = "/001100.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 1 && res[3] == 0 && res[4] == 1 && res[5] == 0) {
text = "Few words are needed—the recent obstacles are being overcome. Now there is peace, so just recuperate and relax. This is a good time to simply be still.";
image = "/001010.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 1 && res[3] == 0 && res[4] == 0 && res[5] == 1) {
text = "This changing first line indicates a time when good fortune follows a sudden change that may have seemed unfortunate at first. If we remain open to all possibilities in a time of crisis, the results can be shockingly positive.";
image = "/001001.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 0 && res[3] == 1 && res[4] == 1 && res[5] == 0) {
text = "Advancing with confidence brings good fortune. Just as a tree draws its power from its roots, even humble beginnings can serve as the foundation for great achievement, given the right attitude. Even though new movement may sometimes induce sadness, there is no regret. Let go of the comforts of the past in favor of the adventurous vitality of creating the future.";
image = "/000110.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 0 && res[3] == 1 && res[4] == 0 && res[5] == 1) {
text = "When lost in a cave, one small candle is better than the light of a thousand dreams. Attempts to soar above obstacles by ignoring them are futile. When obstacles are real, one should not indulge flights of fancy about imagined success. To indulge in fantasies will result in a loss of respect, because attempting to solve large problems is a sign of weakness, unless there is an objective chance at success.";
image = "/000101.bmp";
ei_printf(text);
}
if (res[0] == 0 && res[1] == 0 && res[2] == 0 && res[3] == 0 && res[4] == 1 && res[5] == 1) {
text = "When forces of good begin to prevail, people of influence take notice; and men and women of ability are drawn to the center of action. If you sense such movement, you are advised to join in—but don't let yourself be swept away by the tide of events. Careful movement brings the best fortune.";
image = "/000011.bmp";
ei_printf(text);
}
}
}
#if EI_CLASSIFIER_HAS_ANOMALY == 1
ei_printf(" anomaly score: %.3f\n", result.anomaly);
#endif
print_results = 0;
}
// for image
tft.fillScreen(ST77XX_BLACK);
tft.setRotation(3);
status = reader.drawBMP(image, tft, 0, 0);
reader.printStatus(status); // How'd we do?
if (counter >= 5) {
delay(3000);
}
// end here
// // for screen
tft.fillScreen(ST77XX_BLACK);
testdrawtext(text, ST77XX_WHITE);
if (counter >= 5) {
delay(10000);
}
tft.fillScreen(ST77XX_BLACK);
// end here
}
static int get_enum(const char *Label) {
if (Label == "black") {
return 0;
} else if (Label == "white") {
return 1;
} else {
return -1;
}
}
/**
* @brief PDM buffer full callback
* Get data and call audio thread callback
*/
static void pdm_data_ready_inference_callback(void) {
int bytesAvailable = PDM.available();
// read into the sample buffer
int bytesRead = PDM.read((char *)&sampleBuffer[0], bytesAvailable);
if (record_ready == true) {
for (int i = 0; i < bytesRead >> 1; i++) {
inference.buffers[inference.buf_select][inference.buf_count++] = sampleBuffer[i];
if (inference.buf_count >= inference.n_samples) {
inference.buf_select ^= 1;
inference.buf_count = 0;
inference.buf_ready = 1;
}
}
}
}
/**
* @brief Init inferencing struct and setup/start PDM
*
* @param[in] n_samples The n samples
*
* @return { description_of_the_return_value }
*/
static bool microphone_inference_start(uint32_t n_samples) {
inference.buffers[0] = (signed short *)malloc(n_samples * sizeof(signed short));
if (inference.buffers[0] == NULL) {
return false;
}
inference.buffers[1] = (signed short *)malloc(n_samples * sizeof(signed short));
if (inference.buffers[1] == NULL) {
free(inference.buffers[0]);
return false;
}
sampleBuffer = (signed short *)malloc((n_samples >> 1) * sizeof(signed short));
if (sampleBuffer == NULL) {
free(inference.buffers[0]);
free(inference.buffers[1]);
return false;
}
inference.buf_select = 0;
inference.buf_count = 0;
inference.n_samples = n_samples;
inference.buf_ready = 0;
// configure the data receive callback
PDM.onReceive(&pdm_data_ready_inference_callback);
PDM.setBufferSize((n_samples >> 1) * sizeof(int16_t));
// initialize PDM with:
// - one channel (mono mode)
// - a 16 kHz sample rate
if (!PDM.begin(1, EI_CLASSIFIER_FREQUENCY)) {
ei_printf("Failed to start PDM!");
}
// set the gain, defaults to 20
PDM.setGain(127);
record_ready = true;
return true;
}
/**
* @brief Wait on new data
*
* @return True when finished
*/
static bool microphone_inference_record(void) {
bool ret = true;
if (inference.buf_ready == 1) {
ei_printf(
"Error sample buffer overrun. Decrease the number of slices per model window "
"(EI_CLASSIFIER_SLICES_PER_MODEL_WINDOW)\n");
ret = false;
}
while (inference.buf_ready == 0) {
delay(1);
}
inference.buf_ready = 0;
return ret;
}
/**
* Get raw audio signal data
*/
static int microphone_audio_signal_get_data(size_t offset, size_t length, float *out_ptr) {
numpy::int16_to_float(&inference.buffers[inference.buf_select ^ 1][offset], out_ptr, length);
return 0;
}
/**
* @brief Stop PDM and release buffers
*/
static void microphone_inference_end(void) {
PDM.end();
free(inference.buffers[0]);
free(inference.buffers[1]);
free(sampleBuffer);
}
#if !defined(EI_CLASSIFIER_SENSOR) || EI_CLASSIFIER_SENSOR != EI_CLASSIFIER_SENSOR_MICROPHONE
#error "Invalid model for current sensor."
#endif
//for screen
void testdrawtext(char *text, uint16_t color) {
// tft.setRotation(0);
tft.setCursor(0, 0);
tft.setTextColor(color);
tft.setTextSize(2);
tft.setTextWrap(true);
tft.print(text);
}
//end here
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .