מסיימים לחבר את המכונית ב-Bluetooth — ואז נוהגים בה מדף אינטרנט, ורואים בזמן אמת מה החיישן שלה רואה. We finish connecting the car over Bluetooth — then drive it from a web page and watch, live, what its sensor sees.
ניווט: חצים ← → במקלדת, או הכפתורים למטה · לחצו EN לבדיקת מונחים באנגלית Navigate: ← → arrow keys, or the buttons below · press עב for Hebrew
| אותLetter | משמעותMeaning |
|---|---|
| F B L R | קדימה, אחורה, שמאלה, ימינהforward, back, left, right |
| S | עצירהstop |
| 1 … 9 | מהירות (1 לאט, 9 הכי מהר)speed (1 slow, 9 fastest) |
הפקודה "נשארת" עד הבאה — לכן הדף שולח S כשעוזבים את המקש.A command "stays on" until the next — so the page sends S when you let go of the key.
Web Serial היא יכולת של הדפדפן לפתוח פורט COM — בדיוק כמו ה-Serial Monitor, אבל מתוך דף אינטרנט שאנחנו כותבים.Web Serial lets the browser open a COM port — just like the Serial Monitor, but from a web page we write ourselves.
🕹️ פתיחת מרכז השליטהOpen the command center
בחיבור בכבל הארדואינו מתאפס — הנתונים מתחילים להגיע אחרי כ-2 שניות. זה תקין.On the cable the Arduino resets on connect — data starts after about 2 seconds. That's normal.
| חלקPart | מה הוא עושהWhat it does | נוגעים?Edit? |
|---|---|---|
| 1. CONNECTION | פותח את הפורט, קורא שורות, שולח אותיותopens the port, reads lines, sends letters | מוכןready |
| 2. PROTOCOL | הופך שורה לנתונים: D=23 → D: 23turns a line into data: D=23 → D: 23 | מוכןready |
| 3. DISPLAY | מציג את הנתונים: מספר, צבע, גרףshows the data: number, color, chart | כאן אתם!this is you! |
| 4. CONTROLS | מקלדת וכפתורים ← פקודותkeyboard and buttons → commands | משימות 5, 7missions 5, 7 |
שימו לב: זה אותו מבנה כמו בארדואינו — קלט ← עיבוד ← פלט.Notice: it's the same structure as on the Arduino — input → process → output.
⬇ גרסת התחלה (למסלול ב)Starter version (Track B)
⬇ הגרסה המלאה (פתרון)Full version (solution)
הדפדפן מקבל מה שהגיע עד עכשיו — לפעמים חצי שורה, לפעמים שורה וחצי. לכן אוספים הכול למאגר (buffer), וחותכים ממנו שורה רק כשמגיע \n.The browser gets whatever has arrived so far — sometimes half a line, sometimes a line and a half. So we collect everything into a buffer, and cut a line out of it only when a \n arrives.
let buffer = '';
while (true) {
const { value, done } = await reader.read(); // a chunk
if (done) break;
buffer += value; // add it to the buffer
// cut out every WHOLE line (ends with \n)
let nl;
while ((nl = buffer.indexOf('\n')) >= 0) {
const line = buffer.slice(0, nl).trim();
buffer = buffer.slice(nl + 1); // keep the rest
if (line) handleLine(line);
}
}await = "חכה כאן עד שמגיע משהו" — בלי לתקוע את הדף.await = "wait here until something arrives" — without freezing the page.
// "D=23,M=F,S=160" -> { D: "23", M: "F", S: "160" }
function parseLine(line) {
const data = {};
for (const part of line.split(',')) { // "D=23", "M=F", "S=160"
const [key, value] = part.split('='); // "D", "23"
if (key && value !== undefined) data[key.trim()] = value.trim();
}
return data;
}
function onTelemetry(data) {
if (data.D !== undefined) updateDistance(parseInt(data.D, 10));
if (data.M !== undefined) updateMove(data.M);
if (data.S !== undefined) $('speedText').textContent = data.S;
}const KEYS = { ArrowUp: 'F', ArrowDown: 'B',
ArrowLeft: 'L', ArrowRight: 'R', ' ': 'S' };
let held = null; // which command is held right now
function press(cmd) { if (held === cmd) return; held = cmd; send(cmd); }
function release(cmd) { if (held !== cmd) return; held = null; send('S'); }
document.addEventListener('keydown', e => {
const cmd = KEYS[e.key];
if (cmd && !e.repeat) press(cmd); // once, not 30 times a second
});
document.addEventListener('keyup', e => {
const cmd = KEYS[e.key];
if (cmd) release(cmd);
});פקודה חדשה מקצה לקצה: H.A new command end to end: H.
כשהמרחק יורד מתחת ל-15 ס"מ: הדף מהבהב באדום, או משמיע צפצוף קצר.When the distance drops under 15 cm: the page flashes red, or plays a short beep.
רמז: document.body.style.background, או AudioContext לצליל. ואל תצפצפו 5 פעמים בשנייה — רק כשנכנסים לאזור.Hint: document.body.style.background, or AudioContext for sound. And don't beep 5 times a second — only when entering the zone.
הבעיה: Bluetooth נופל באמצע נסיעה — והמכונית ממשיכה (הפקודה "נשארת").The problem: Bluetooth drops mid-drive — and the car keeps going (the command "stays on").
level0_fake_car.ino מדבר בדיוק באותה שפה כמו המכונית — כך אפשר לפתח את הדף ליד השולחן, רק עם ארדואינו וכבל USB.level0_fake_car.ino speaks exactly the same language as the car — so you can develop the page at your desk, with just an Arduino and a USB cable.
| פוטנציומטרPotentiometer | לאןTo |
|---|---|
| רגל אמצעיתmiddle leg | A0 |
| רגל קיצונית אחתone outer leg | 5V |
| רגל קיצונית שנייהother outer leg | GND |
| מה רואיםWhat you see | מה בודקיםWhat to check |
|---|---|
| "הדפדפן לא תומך ב-Web Serial""This browser doesn't support Web Serial" | Chrome או Edge, במחשב. לא Firefox, לא Safari, לא טלפוןChrome or Edge, on a computer. Not Firefox, Safari, or a phone |
| "לא הצלחתי לפתוח את הפורט""Couldn't open the port" | ה-Serial Monitor פתוח? (או לשונית אחרת עם הדף). סגרו ונסו שובIs the Serial Monitor open? (Or another tab with the page.) Close it and try again |
| מחובר, אבל המספרים לא זזיםConnected, but the numbers don't move | המכונית מריצה את car_telemetry.ino? בחרתם את הפורט הנכון? בכבל — חוטי ה-HC-05 מנותקים?Is the car running car_telemetry.ino? Right port? On the cable — are the HC-05 data wires unplugged? |
| הנורית בדף אדומה, "הודעה אחרונה" עולהThe page's light is red, "last message" keeps growing | הקשר נפל: סוללות, טווח, או שהמודול התנתק. ניתוק ← התחברות מחדשThe link dropped: batteries, range, or the module disconnected. Disconnect → connect again |
| הנתונים מגיעים, המכונית לא מגיבה לחציםData arrives, the car ignores the arrows | לחצתם קודם על שדה (למשל המהירות)? לחצו על רקע הדף. ביומן רואים > F?Did you click into a field (e.g. speed) first? Click the page background. Does the log show > F? |
| שיניתי את הקוד ושום דבר לא השתנהI changed the code and nothing changed | שמרתם? רעננו (F5). ואם הדף ריק או תקוע — F12 ← ConsoleSaved? Refresh (F5). And if the page is blank or stuck — F12 → Console |
פרוטוקול פשוט — אות אחת לפקודה, שורה אחת להודעה — מאפשר לכל תוכנה לדבר עם המכונית: Serial Monitor, אפליקציה בטלפון, או דף אינטרנט שכתבנו בעצמנו.A simple protocol — one letter per command, one line per message — lets any program talk to the car: the Serial Monitor, a phone app, or a web page we wrote ourselves.
💻 קבצי הקוד של השיעור (ארדואינו) — הורדה והסברThis lesson's Arduino code — download & walkthrough
תודה — נתראה בפעם הבאה! 👋Thanks — see you next time! 👋
הרלד "שן כחולה" (Harald Bluetooth) היה מלך דני במאה העשירית, שאיחד את שבטי דנמרק תחת שלטון אחד. כשחיפשו שם לטכנולוגיה שאמורה לאחד מכשירים של חברות שונות — השם שלו התאים.Harald "Bluetooth" was a 10th-century Danish king who united the tribes of Denmark under one rule. When they looked for a name for a technology meant to unite devices from different companies — his name fit.
הלוגו הוא שתי אותיות רוניות — H ו-B, ראשי התיבות של Harald Bluetooth — מחוברות לסימן אחד.The logo is two runic letters — H and B, Harald Bluetooth's initials — joined into one symbol.
כאן הקפיצות איטיות פי ~600 מהמציאות. אדום = שני הזוגות נפלו על אותו ערוץ באותו רגע — ובקפיצה הבאה זה כבר מסתדר.Here the hops are ~600× slower than reality. Red = both pairs landed on the same channel at the same moment — and by the next hop it's sorted out.
| Bluetooth Classic | Bluetooth Low Energy (BLE) | |
|---|---|---|
| מתי נולדBorn | 1999 (גרסה 1.0)1999 (version 1.0) | 2010 (גרסה 4.0)2010 (version 4.0) |
| מה הוא טוב בוGood at | זרם נתונים רציף: אוזניות, רמקולים, "כבל סיריאלי"a continuous data stream: headphones, speakers, a "serial cable" | הודעות קצרות ומעט סוללה: שעונים, חיישנים, צמידי כושרshort messages on little battery: watches, sensors, fitness bands |
| ערוציםChannels | 79 × 1 MHz | 40 × 2 MHz |
| "שפה" לנתוניםData "language" | פרופיל SPP — מתנהג בדיוק כמו פורט סיריאליthe SPP profile — behaves exactly like a serial port | GATT — "תיבות" של ערכים שקוראים וכותביםGATT — "boxes" of values you read and write |
| מודולים לארדואינוArduino modules | HC-05, HC-06 | HM-10 |
| מי מתחברWho connects | Windows, Mac, Android. לא אייפוןWindows, Mac, Android. Not iPhone | כולם — כולל אייפון, וגם דפדפן (Web Bluetooth)everyone — including iPhone, and the browser too (Web Bluetooth) |